View Full Version : stop posting the form in new window if login is incorrect(show an error msg instead)

01-27-2009, 04:28 PM
dear readers,

the code below belongs to a form where users can input their username and password to login to their webmail service.

it uses target="_blank" to open the new window for the logged in users. it also opens a new window even if the login information is incorrect. whereas it should be remaining in the current window displaying an error msg "Your login attempt failed!" without opening a new window.

As you can guess, I am not very good in this.

i posted it here cause maybe javascript may be introduced to solve this.

help me out please.


<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<center><table width="200" border="0" cellspacing="2" cellpadding="0"><tr><td bgcolor="000000" width="100%" align=center><span class="grey"><font face=arial size=4><b>WebMail</b></span></font></tr></td></table></center><br>

<form action="Login.php" method="POST" target="_blank">
// Show an error if the login failed
if(($_GET['failed'] == "1") or ($error == 1)){
echo '<font color="#FF0000">Your login attempt failed!</font><br />';
<input type="hidden" name="domain" value="domain.com" size="20" /><br />
<font face=arial size=2><b>Username: </b></font><input type="text" name="username" value="" size="20" /><br />
<font face=arial size=2><b>Password: </b></font><input type="password" name="pass" value="" size="20" /><br />

echo '<input type="hidden" name="failurl" value="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?failed=1">';
<select name="port" style="display:none;">
<option value="2095">Webmail</option>
<option value="2096">Secure Webmail</option>
</select><br />
<input type="submit" value="Login" />




01-27-2009, 04:53 PM
The form has no clue if the data is correct so it will post to a new window.

Only way you can make sure the data is correct is use an Ajax call to post back to the server. If it is, you can call window.open or post the form. If the login is incorrect you show an error message on the page.


01-28-2009, 07:57 AM
thanks for the reply A1.

the form goes to login.php to check if the data is correct or not.

as i am relatively new, can you please give an example of an ajax call?

thanks in advance.


01-31-2009, 01:10 PM
seems like no one interested to help. or no one has actually a solution to help!!!