I have a form like this:
index.php
<form method="post" action="send.php"> <textarea name="msg" id="msg"></textarea> <input type="submit" value="Send" /> </form>
So, if I enter something in textarea and clicked on "Send", it is submitted to "send.php" page. But I want to include another button for previewing it. That is, when this button is clicked, the above form is submitted to "preview.php" which will be opened in a new blank window/tab (original page ie. index.php will be there intact). This is to display a preview of the message, that the user is going to send.
I do not know how to do this.
To link a submit button to another webpage using HTML Form Tags: Using the HTML Form's Action Attribute, we can link the submit button to a separate page in the HTML Form element. Here, declare/write the “Submit button” within HTML Form Tags and give the File Path inside the HTML form's action property.
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.
Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.
Use Javascript to temporarily change the action and target:
<form method="post" action="send.php" id="idOfForm"> <textarea name="msg" id="msg"></textarea> <input type="submit" value="Send" /> </form> <button onclick="doPreview();">Preview</button> <script type="text/javascript"> function doPreview() { form=document.getElementById('idOfForm'); form.target='_blank'; form.action='preview.php'; form.submit(); form.action='send.php'; form.target=''; } </script>
There is now an attribute for the submit input that handles this:
<input type="submit" formaction=”differentThanNormalAction.php”>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With