divinedesigns1 Posted September 15, 2018 Share Posted September 15, 2018 (edited) how can i link a function to a php form so it can run the function on submit i know you have to add the function in the action="" but is there anything i need add to make this work correctly? Edited September 15, 2018 by divinedesigns1 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 17, 2018 Share Posted September 17, 2018 No, you do not add the function in the action. If you think you know that, then you're on the wrong path. The action should be the URL of a PHP file on the server. If you want to run a particular function in that file, then use a hidden form input or something with a name that you check for, and a value that tells you which function to execute. You do that the same way you use with any other logic, you can use a series of if statements, or a switch statement, or you can have an array of allowed functions and call it just by passing the name. e.g.: $allowed_functions = ['func1', 'func2', 'func3']; if (in_array($_POST['function_name'], $allowed_functions)) { {$_POST['function_name']}(); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now