Practical Web Programming

Friday, January 23, 2009

How to Submit an HTML Form to a New Window

Sometimes, for whatever reason, you want to submit an HTML form to a new window. To do this, you just need to add the attribute target='_blank' to your HTML form. Here's an example.

<form target='_blank' method='POST' action='index.php'>
<br/>First Name: <input type='text' name='firstname' value='' />
<br/>Last Name: <input type='text' name='lastname' value='' />
<br/><input type='submit' name='submit' value='Submit' />
</form>


And here's the PHP version.

<?php

print "<form target='_blank' method='POST' action='index.php'>
<br/>First Name: <input type='text' name='firstname' value='' />
<br/>Last Name: <input type='text' name='lastname' value='' />
<br/><input type='submit' name='submit' value='Submit' />
</form>";

?>


Once you click the Submit button, the browser will submit and open a new window where the form will be handled.

0 comments:

Recent Post