Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.