• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Magic Form - Need Explanation

I have coded two forms and please note **they are behaving as I would like**, but I don't know why. If I put the code here can someone explain why it is working.

I have a simple form on a view, with its own controller like this
<?=form_open('newslettersignup'); ?>
          <h2>Newsletter Signup</h2>
          &lt;input type="text" name="name" maxlength="25"&gt;&lt;/input>
          &lt;input type="text" name="email" maxlength="50"&gt;&lt;/input>
          &lt;input class="button" type="submit" value="sign up"&gt;&lt;/input>
          &lt;?=form_close() ?&gt;

When someone fills in the values and clicks on the submit button, it goes to a different controller called newsletter signup which shows another form like the one below.

&lt;?=form_open('newslettersignup'); ?&gt;
   <h2>Newsletter Signup</h2>
   &lt;input value="&lt;?=set_value('name');?&gt;"  type="text" name="name"  maxlength="25"&gt;&lt;/input>
   &lt;input value="&lt;?=set_value('email');?&gt;" type="text" name="email" maxlength="50"&gt;&lt;/input>
   &lt;input class="button" type="submit" value="Send"&gt;

The second form contains the values for name, email and country that the first form contained, which is what I wanted to happen. My question is - how did I do this? What is making the second form contain the same values as the first form when I don't think I've done anything explicitly to make this happen. Is it the set_value call?

Apologies if this sounds daft, but I've done what I want to do with no idea how I did it. Not really sure what set_value does when the values were in another, separate form.

[eluser]GSV Sleeper Service[/eluser]
set_value is doing that. it will set the value to whatever is in the current $_POST, if the name exists. it also looks at the validation values too, neat! The user guide doesn't mention this at all...
from the source code -
* Form Value - this needs updating too, should be 'Set Value'
* Grabs a value from the POST array for the specified field so you can
* re-populate an input field or textarea.  If Form Validation
* is active it retrieves the info from the validation class
* @access    public
* @param    string
* @return    mixed
take a look at system/helpers/form_helper.php to see what's going on.

Thank you - GSV Sleeper Service.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.