Create html form with two action patches

How can I create an html form for which the action attribute has 2 destinations. I want when the user clicks on the bottom view, checks if the user enters wrong data, the page navigates to other pages with window.location and if the user inserts the correct input, goes to the main page with the same instruction.

+3


source to share


2 answers


First of all, what do you mean by correct input? Main form data validation happens on the server side, not on the client side. you are better off using the client side just for simple checking, like typos.

No need for two destination pages (as you call it). You can use the standard action attribute, which is the page on the server to which you submit your form data.



there, you have the ability to decide which condition needs which action and send data (and then the user) to the desired page / action.

+1


source


Sample code for a form

<form id='myform' action='action.php' method='POST' target='formresponse'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' maxlength="50" /><br/>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' maxlength="50" /><br/>
<input type='button' name='Submit' value='Submit' />
</form>

<iframe name='formresponse' width='300' height='200'></frame>

      



Several actions

function SubmitForm()
{
     document.forms['contactus'].action='action1.php';
     document.forms['contactus'].target='frame_result1';
     document.forms['contactus'].submit();

     document.forms['contactus'].action='action2.php';
     document.forms['contactus'].target='frame_result2';
     document.forms['contactus'].submit();
     return true;
}

      

+1


source







All Articles