Php – Call form submit action from php function on same page

formshtmlphpwebforms

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-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
  }

What is the proper way to call the submit function?

Best Solution

After you fix your radio group so they all have the same name:

if (isset($_POST['rsvp-radio'])) {
    rsvpsubmit();
}