admin管理员组文章数量:1323330
I had two forms
- login form
- Registration form
login form has the username and password fields and registration form consists controls for registration like username, city, country, etc.,
- Also, I have some hidden controls like
<input type="hidden" name="ctrl1" />
<input type="hidden" name="ctrl2" />
<input type="hidden" name="ctrl3" />
<input type="hidden" name="ctrl4" />
Which is dynamically generated using PHP Code.
What I want is, When the user click login form's submit or the registration form's submit, the hidden controls data should also be Posted.
I had two forms
- login form
- Registration form
login form has the username and password fields and registration form consists controls for registration like username, city, country, etc.,
- Also, I have some hidden controls like
<input type="hidden" name="ctrl1" />
<input type="hidden" name="ctrl2" />
<input type="hidden" name="ctrl3" />
<input type="hidden" name="ctrl4" />
Which is dynamically generated using PHP Code.
What I want is, When the user click login form's submit or the registration form's submit, the hidden controls data should also be Posted.
Share edited Nov 18, 2015 at 15:08 Pᴇʜ 57.8k10 gold badges55 silver badges75 bronze badges asked Aug 17, 2010 at 14:40 RajasekarRajasekar 19k35 gold badges109 silver badges140 bronze badges 1- 1 You should consider adding the hidden controls to the form being submitted. The only way to post two forms is via JavaScript; you'll wind up having to fire an AJAX request before your main form is submitted, and things will break terribly if the user has JS disabled. – user229044 ♦ Commented Aug 17, 2010 at 14:43
3 Answers
Reset to default 4Insert the hidden inputs into both forms when you generate the page:
<form id='form1' action='' method='post'>
<input type='hidden' name='h1' value='v1' />
<input type='hidden' name='h2' value='v2' />
<input type='hidden' name='h3' value='v3' />
<input type='submit' name='submit' value='Submit Form 1' />
</form>
<form id='form2' action='' method='post'>
<input type='hidden' name='h1' value='v1' />
<input type='hidden' name='h2' value='v2' />
<input type='hidden' name='h3' value='v3' />
<input type='submit' name='submit' value='Submit Form 2' />
</form>
Use this example, definitely it will help you.
<SCRIPT LANGUAGE="JavaScript">
function runscript()
{
document.form1.submit();
document.form2.submit();
}
</SCRIPT>
<BODY>
<FORM METHOD=POST ACTION="http://localhost/login.php" NAME="form1">
<INPUT TYPE="text" NAME="text1">
</FORM>
<FORM METHOD=POST ACTION="http://localhost/register.php" NAME="form2">
<INPUT TYPE="text" NAME="text2">
</FORM>
<INPUT TYPE="button" value="Submit" onClick="runscript()">
</BODY>
Use jQuery's serialize on one of the forms.
本文标签: phpHow to post two form with single submit clickStack Overflow
版权声明:本文标题:php - How to post two form with single submit click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742139840a2422533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论