Some times we may need to submit HTML form to a pop up window. Let’s take a look into the details. For example I have a HTML form.
<form action="thank-you.php" method="post" name="contactForm">Name : <input id="name" name="name" type="text" /> E-mail : <input id="email" name="email" type="text" /> <input type="submit" value="Submit" /> </form>
We may submit this form to a blank window by setting target="_blank"
, but when we need to submit the form to a pop up window then we should do some extra code. Let’s try.
Step one: Defining a JavaScript function
function openWindow(url, wname, width, height) { window.open(url, wname, "height=" + height + ",width=" + width + "location = 0, status = 1, resizable = 0, scrollbars=1, toolbar = 0"); return true; }
Above function opens a pop up window according to the supplied arguments. There is a tricky thing. 'name'
is a keyword in JavaScript. We should not put the variable name as 'name'
. IE reports error if we put name as a variable name.
Step two: Setting the form attributes
Now we set the form attributes like bellow
<form action="/thank-you.php" method="post" name="contactForm" target="popupWin">
Step three: Preparing thank you page
Now we are ready to prepare the thank-you.php
page for processing the form data.
Some more things must follow for security and to protect spamming. We should apply both JavaScript and server side validation into the form, protect spamming and XSS.
Leave a Reply