Reputation: 943
I have deigned a simple HTML form but i want to submit it to a PHP to process but I want to submit the form not with the help of Button / Submit but with the help of anchor Tag
<a href="#">Submit</a>
how to do it the form is like
<form action="" method="post">
<input type="text" name="name" />
<input type="email" name="email" />
<a href="#">Submit</a>
</form>
I want to post this form to the same page
Upvotes: 0
Views: 124
Reputation: 126
Is there a particular reason where you need to have the form submit via an anchor tag?
As has been stated above, you can use JavaScript to submit the form, but if you run into the rare case of a user having JavaScript off, the form becomes unusable. I'd stick with the suggestion of styling the button to look like a link using CSS.
Upvotes: 0
Reputation: 3837
if you REALLY want to do it this way you have to use javascript to submit the form in some way.
You can either add an onclick event to the link or you can add an onkeypress to the text fields so when the user hits ENTER it submits the form.
However, this is typically bad practice. Why not just use the button or input[type="submit"] tag? If the clients disable javascript then they'll never be able to submit your form, unless that's your goal.
Upvotes: 0
Reputation: 104775
In my opinion, I would keep using a button
of type submit
and just style it to look like a link with CSS.
button#submit {
background:none;
border:none;
padding:0;
color:#069;
text-decoration:underline;
cursor:pointer;
}
<button id="submit" type="submit">Submit</button>
Upvotes: 2
Reputation: 2314
Javascript can help you.
<a href="javascript:void(0)" onclick="this.parentNode.submit();">Submit</a>
But of course you can style your submit button with CSS
Upvotes: 0