Call form call from php function on same page

I am working on a simple web application. To reduce the number of files, I want to put (php) code for the form submission function on the same page as the form. Something like that:

<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 correct way to call a submit function?

+5
source share
2 answers

After you correct your radio group, they all have the same name:

if (isset($_POST['rsvp-radio'])) {
    rsvpsubmit();
}
+8
source
<?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
  }
?>
+7
source

All Articles