Submit Form To Another Page (which Is Different From The Page Used In Action)
I have a form like this: index.php
Solution 1:
Use Javascript to temporarily change the action and target:
<formmethod="post"action="send.php"id="idOfForm"><textareaname="msg"id="msg"></textarea><inputtype="submit"value="Send" /></form><buttononclick="doPreview();">Preview</button><scripttype="text/javascript">functiondoPreview()
{
form=document.getElementById('idOfForm');
form.target='_blank';
form.action='preview.php';
form.submit();
form.action='send.php';
form.target='';
}
</script>
Solution 2:
There is now an attribute for the submit input that handles this:
<inputtype="submit" formaction=”differentThanNormalAction.php”>
Solution 3:
Give your form an ID (form1). The action of the current form can be controlled like this:
functionsetPreview() {
$('#form1').attr('target','_blank')
$('#form1').attr('action','http://yourpreviewurl.php')
$('#form1').submit()
}
functionsetSubmit() {
$('#form1').attr('target','')
$('#form1').attr('action','http://yourposturl.php')
$('#form1').submit()
}
Have two buttons, both type="button"
, one to call setPreview and another to call setSubmit
Solution 4:
You can use JavaScript to change the action of the form when the button is clicked and then submit it.
Or simply submit the form via AJAX and then redirect after you get a response.
Solution 5:
<formonreturn="someJavascriptFunction()"action=""method="">
creating a js function able to open this preview page
Post a Comment for "Submit Form To Another Page (which Is Different From The Page Used In Action)"