I am trying to get this to work:
<?php
function afunction()
{
some php code that generates an unlock code;
}
echo "<form name='input' action='afunction()' method='post'>";
{
echo "Enter serial number:";
echo "<input type='text' name='serial'>";
echo "<input type='submit' value='Generate Unlock Code'>";
echo "<br/>";
}
echo "</form>";
?>
but I get a 404 error "Can't find page afunction()"
How do I execute afunction() from the form action??
G
Calling a php function from an html form action
Moderator: General Moderators
Re: Calling a php function from an html form action
You can't execute the PHP function directly like that, a form action field requires a page to redirect to.
Easiest way would be to create a PHP page that contains the afunction() (e.g. afunction.php) and pass the variables to it. Then call afunction() within the new PHP page.
Alternatively, create afunction() in Javascript rather than PHP and run it when the submit button is clicked. This may not be the best option though, as you probably want to hide the code that generate the unlock code.
Easiest way would be to create a PHP page that contains the afunction() (e.g. afunction.php) and pass the variables to it. Then call afunction() within the new PHP page.
Alternatively, create afunction() in Javascript rather than PHP and run it when the submit button is clicked. This may not be the best option though, as you probably want to hide the code that generate the unlock code.