我正在开发一个简单的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
}
调用提交函数的正确方法是什么?
答案 0 :(得分:8)
修复您的广播组后,它们都具有相同的名称:
if (isset($_POST['rsvp-radio'])) {
rsvpsubmit();
}
答案 1 :(得分:7)
<?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
}
?>