Pass Data from Form to Controller and Back Again.
When the form is submitted if there's any required fields (or wrong Captcha) I need to be able to return to the calling form and re-populate the fields that were filled in so the visitor doesnt lose entered data and generate some kind of response saying "Hey fill in all your fields!"
Another thing that perplexes me is the return call. What do you return to? Index.php doesnt have any code in it, just uses some dispatcher and then somehow inserts/themes my external form. How you do even go about getting variables from the controller with all the magic behind the scenes?
I'm thinking either hidden fields (which I tried, but I must have some scope issue because the hidden fields never have the values that the php code above have) or I thought about session variables and $GLOBALS and I dont understand how to get these to work.
I have spend gobs of time looking at lots of forum posts and tried to do what they are doing and just cant get it to work. Even a simple working example would be wonderful.
I'll try to keep the code as short as possible for readability. Any help would be most appreciated. Please see attached text files.
Thanks so much in advance!
The controller is the key to repopulating fields. When the external form is posted, the controller is the object that captures the value via post.
// form post method (note the action, this calls the controller)
<form name='contactus' id='contactus' method="post" action="<?php echo $this->action('submit_form')?>" onsubmit="return validate(this);">
*Note: The controller must have a public function named: "action_submit_form()" or it wont work
// Controller variable to catch the posted value
While in the controller if you find that the captcha is wrong you will need to "set" a variable so that the external form block can gain access to this variable. This is done so the visitor doesnt lose data.
Ex: (*Still in the controller)
if ($errors == 0)
// either send results to email or database
// set variable for re-population
The following is a field in the external form block whose value is now the variable that was set in the controller.
<input type="text" id="fHomePhone" size="25" name="fHomePhone" value="<?php echo $fHomePhone; ?>">
The variable $fHomePhone in the external form block does not have a value when it first loads. It will only get "set" in the controller if there is an error.
Hope that is not clear as mud :)