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
Share on other sites

Where is uservals being set ?

 

Right before all that. It just takes the posted values and makes userVals out of it.

 

I got it though, you replied just as I figured it out.

 

Thanks for your response

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.