I'm working on a simple web application. In order to reduce the number of files, I want to put (php) code for a form submit function into the same page as the form. Something like this:
<body>
<form id = "rsvp-st开发者_如何学Catus-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
}
What is the proper way to call the submit function?
After you fix your radio group so they all have the same name:
if (isset($_POST['rsvp-radio'])) {
rsvpsubmit();
}
<?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
}
?>
精彩评论