Jump to content

NEED HELP in function and button error


leolim

Recommended Posts

i have created a button in my form (type=button) and on the onClick event, I need to execute some php code or some particular function

I don't want to create a submit button instead because cause i want to call different function when different button clicked how should i do that?

 

<head> 
<title>My Variables HTML Form</title> 
</head> 
<body> 
<h4>My HTML Form</h4> 
<?php
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
    

    echo "SUBMITTED BUTTON";
    //calling function
   display();
} 
else {
   echo "ME BUTTON";
    
    profile();
   
}

function display()
{
echo "you called display function";
}

function profile()
{
echo "you called Profile function";
}
?> 	


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Name:  <input type="text" name="personal[name]" /><br />
    Email: <input type="text" name="personal[email]" /><br />
        <input type="button" name="action" value="submitted" />
    <input type="button" name="submit" value="submit me!" />
</form>



</body> 
</html>

 

The program could not work and once runned it display directly "ME BUTTONyou called Profile function"  how to correct the program so it runs only when it clicked according to the button triggered?

Link to comment
https://forums.phpfreaks.com/topic/68294-need-help-in-function-and-button-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.