Page 1 of 1
PHP form on link click
Posted: Sun Feb 05, 2006 6:34 am
by VBmaster
I'd like to know is it possible to run a form code in php on link click, and not a button or an image?
If it is, please post how!
Thanks,
VBmaster
Posted: Sun Feb 05, 2006 8:41 am
by RobertGonzalez
No, you can't submit a form using PHP. Form submits are generated by the client (a users computer) while PHP processes on the server. You can use simple javacsript to emulate a form submission by using a text link instead of a button.
Code: Select all
// Link submit button
function textSubmit( objForm )
{
var fName = document.getElementById(objForm);
fName.submit();
}
To use this function, add it as a link in your form. Make sure you give your form an ID also...
Code: Select all
<form method="post" action="nextpage.php" id="the_first_form" name="the_first_form">
<input type="text" name="text1" value="Some default value for text1" /><br />
<a href="javascript: textSubmit('the_first_form');" title="Submit this form using this text link">Submit this form!</a>
</form>
I think an alternative method of calling the function would be to use the JS
this keyword instead of the actual form ID, but I am not totally certain.