sta*_*ets 5 html php forms webforms
我正在开发一个简单的Web应用程序.为了减少文件数量,我想将表单提交功能的(php)代码放入与表单相同的页面中.像这样的东西:
<body>
<form id = "rsvp-status-form" action = "rsvpsubmit" method = "post">
<input type="radio" name="rsvp-radio" value="yes"/> Yes<br/>
<input type="radio" name="ravp-radio" value="no" checked/> No<br/>
<input type="radio" name="rsvp-radio" value="notsure"/> Not Sure<br/>
<input type="submit" value="submit"/>
</form>
</body>
<?php
function rsvpsubmit() {
// do stuff here
}
Run Code Online (Sandbox Code Playgroud)
调用提交函数的正确方法是什么?
修复无线电组后,它们都具有相同的名称:
if (isset($_POST['rsvp-radio'])) {
rsvpsubmit();
}
Run Code Online (Sandbox Code Playgroud)
<?php
if (isset($_POST['rsvpsubmit'])) {
//do something
rsvpsubmit();
}
else {
//show form
?>
<body>
<form id="rsvp-status-form" action="?rsvpsubmit" method="post">
<input type="radio" name="rsvp-radio" value="yes"/> Yes<br/>
<input type="radio" name="rsvp-radio" value="no" checked/> No<br/>
<input type="radio" name="rsvp-radio" value="notsure"/> Not Sure<br/>
<input type="submit" value="submit"/>
</form>
</body>
<?php
}
function rsvpsubmit() {
// do stuff here
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43125 次 |
| 最近记录: |