how to call function when submitting form?

Hi!

I cannot figure out how to call a function when submitting a form

index.php
[php]

function myFunction() {
echo $_POST[‘first_name’];
}

[/php]

and I want to have this function and codes on the same page index.php

how can I also display form when it is only blank? or on first page visit?

I believe you’re mixing PHP and JavaScript together and getting confused, if that is what you’re trying to do?

Hello Mr.Strider64,

Yes sorry I was mixing JavaScript with PHP, let me change question.

how can I call a function after clicking submit button using PHP only?
but sends data of the form on the same page? (index.php)

[php]

<?php //The function would usually be in a separate file function myFunction($fname) { //Output the value we got echo $fname; } //Check if the form has been submitted if (isset($_POST['submit'])){ //Run the function and pass the post value myFunction($_POST['fname']); } ?> [/PHP]

Thank you Mr.scotlpool2003!

it works! this is what I wanted to do. :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service