Jump to content

Help making a form sticky


TOA

Recommended Posts

Hi.

 

I need some help. I don't know if I've just been staring at this for too long or what, but I can't figure out how to make the form below sticky (and by that I mean the values stay if there is an error and redirect). I get lost in all the arrays :)

 

Here's the code for my form:

       $num = intval($_SESSION['num']);
if (isset($_SESSION['PlanError'])) { echo "$_SESSION[PlanError]<br />"; }
echo "<form action='' method='POST'>";
for ($i=1; $i < $num + 1; $i++) {
                      <table>
                      <tr><th>General Plan Info</th><th>Supplemental Benefits</th></tr>
                      <tr><td class="half">Plan Name <input type="text" name="<?php echo 'P['.$i.'][name]';?>" value="<?php  checkArraySticky('1', 'name'); ?>" /><br />
                      </table>
        }
      echo '<input type="submit" name="continue" value="  Continue  " class="button" /><input type="submit" name="save" value="   Save and finish later  " class="button"  />';
      echo "</form>";

 

There's a few more fields in there, but they're not needed for the example, they all work the same way.

 

So as you can see, the user post's a number from another script and this takes it and shows that many versions of it. So all the inputs are arrays like $P[1][name] for example (meaning plan 1 name)

 

I just can't figure out how to make it sticky. I tried throwing everything in a session but can't get it to work.

 

Here's what I tried to make it sticky:

function checkArraySticky($num, $value) {
if (isset($_SESSION['userVals']['P'][$num][$value])) { echo $_SESSION['userVals']['P'][$num][$value]; }
}

 

 

Any suggestions?

 

*** EDIT *** Nevermind, that worked, I just wasn't calling the function right

 

 

Link to comment
https://forums.phpfreaks.com/topic/241836-help-making-a-form-sticky/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.