Scully
Scully

Reputation: 25

Submit a form to a specific function in a php file

So I have a form in index.php

  <? requireonce("action.php"); ?>
  <form action="action.php" method="post">
    //stuff
  </form>

I also have a function to handle that form in action.php

<? 
   function formHandle(){
      //stuff
   }
?>

How do I pass the form to formHandle() entirely within index.php? I don't want to call formHandle() in action.php because it's required in index.php - and I don't want it to run upon page opening.

Upvotes: 2

Views: 1284

Answers (3)

deceze
deceze

Reputation: 522099

You cannot submit "to a function". Browsers don't care about server-side languages. Browsers communicate via HTTP. HTTP has no concept of "functions" or specific programming languages. You submit something to a URL, and the server handles whatever happens at that URL.

Upvotes: 1

M Khalid Junaid
M Khalid Junaid

Reputation: 64476

You can do so in action.php

<?php

if(isset($_POST['myform'])){

formHandle();  // call to a function
}

?>

Upvotes: 2

Expedito
Expedito

Reputation: 7795

Change your action to index.php and call formHandle from within index.php.

<? require_once("action.php"); ?>
<form action="index.php" method="post">
    //stuff
</form>

Upvotes: 0

Related Questions