简体   繁体   English

如何将值从一页传递到另一页上的jQuery表单提交

[英]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... 我正在尝试使用php&jquery构建表单,但是对于如何处理其中的jquery部分我有些困惑...

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... 我还没有任何php或jquery,这只是html标记的简化版本...

//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. 因此,在下一步文件中,您需要做的就是设置隐藏字段,然后循环遍历post var,然后通过jquery设置每个变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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