The live headers add-on for Firefox may provide useful information for debugging this. forward() sends a redirect header to the browser so checking that header is a good next step.
If you allow me to say that, I'll say it: WTF?! I decided to delete the file and to copy/paste the code into a new one with the same name. Guess what? The redirection is working now...
Anyway, it's working fine now.
@Cash, thanks for the tip but apart showing me that the redirect request wasn't sent, it hadn't really given other useful information. But thanks again :).
In 1.8 there is a built in system for it called "Sticky Forms"
Info on that can be found here: http://blog.elgg.org/pg/blog/cash/read/169/elgg-18-sticky-forms
For 1.7 there's nothing standard, but it's very easy to do using session variables.
In your action where you're processing the inputs, set them as session variables like this:
$city = $_SESSION['form_name']['city'] = get_input('city');
This way you can do your sanity checks, and if anything fails send them back with
forward(REFERRER);
and the session will keep the data.
If the data all passes, at the end of your action before sending them away you just unset the session variable (just the part you set, not the entire session!!!)
unset($_SESSION['form_name']);
On your form you will have inputs, before calling the view (if using views to generate the inputs) or displaying the html determine what the default value will be:
$default = <default value if you're coming to the form for the first time>;
if(!empty($_SESSION['form_name']['city']){
$default = $_SESSION['form_name']['city'];
}
elgg_view('input/text', array('internalname' => "City", 'value' => $default));
//and then unset the session again so if they leave the page it's not put in next time
unset($_SESSION['form_name']['city']);
I hope that helps.
Thanks, I'll try that solution I'm wondering why I didn't think about the sessions but it's probably because when I learned PHP, the guy never spoke about them.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.