PHP form on link click

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VBmaster
Forum Newbie
Posts: 2
Joined: Sun Feb 05, 2006 2:02 am

PHP form on link click

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply