简体   繁体   中英

how to pass values from one page to another on jquery form submit

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>
<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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM