views:

458

answers:

2

I'm trying to build a form using php & jquery, but I'm a little confused as to what to do with the jquery portion of it...

Basically, when the user submits the first form, I want to direct them to the "next step" form, but I want to retain the values submitted from the first one in a hidden input field...

If someone can either show me how or point me to a good tutorial, I'd appreciate it...

I don't have any of the php or jquery yet, and this is just a simplified version of the html markup...

//first.php
<form name="form1" method="post" action="second.php">
<input type="text" name="name" value="" />Name
<input type="submit" name="step1" value="Next" />
</form>

//second.php
<form name="form2" method="post" action="process.php">
<input type="hidden" name="name" value="{$_POST['name']}" />
<input type="text" name="message" value="" />message
<input type="submit" name="step2" value="Finish" />
</form>
A: 
<input type="hidden" name="name" value="{$_POST['name']}" />

should be,

<input type="hidden" name="name" value="<?php echo $_POST['name']}; ?>" />

and also sanitize the input, if you want

Anurag
Little typo (}), it should be :<input type="hidden" name="name" value="<?php echo $_POST['name']; ?>" />
Benjamin Delichère
A: 

I don't no if there is a better way to do that. But, when I need to do such thing, I do in this way:

<script>
<?php
foreach($_POST as $key => $valule)
{
    echo "$('$key').val('$value')";
}
?>
</script>

So, in your nextstep file, all you'll need to do is set up the hidden fields and then just loop through the post vars and set each one via jquery.

Keyne