This is a long example, but basically I am trying to get a form to submit using document.forms[0].submit() in FF 2.0. It may or may not work in other browsers but it certainly does not work in this one.
Have a look at the end of the post for more info:
I have tried various methods including:Code:<? require_once('../../inc/com/woyano/jv/ezsql/shared/ez_sql_core.php'); ?> <? require_once('../../inc/com/woyano/jv/ezsql/mysql/ez_sql_mysql.php'); ?> <? require_once('../../inc/am/gocountry/util/Database.class.php'); ?> <? require_once('../../inc/am/gocountry/util/Security.class.php'); ?> <? require_once('../sajax-0.12/php/Sajax.php'); // include for checking if email is already registered ?> <? session_start(); ?> <? /** * SAJAX */ /** * checkForm * * checkForm checks for 2 things * 1. That the email supplied exists in the dB * 2. That the email (assumed 1. is true) & password can be authenticated */ function checkForm($email,$password){ /** * Associative array key isUniqueEmail is ref to the * User class method of the same name. */ $array[0] = false; /** * Associative array key isAuthenticUser is ref to the * Security class method of the same name. */ $array[1] = false; /** * See if $email isUniqueEmail */ $tmpUser = new User; $result = $tmpUser->isUniqueEmail($email); $array[0] = $result; /** * See if $email & $password makes our end-user isAuthenticUser */ $tmpSecurity = new Security; $result = $tmpSecurity->isAuthenticUser($email,$password); $array[1] = $result; /** * Garbage collection */ $tmpUser = null; $tmpSecurity = null; /** * Send result */ return $array; } /** * GET is not the method of choice, but POST is not well supported yet. */ $sajax_request_type = "GET"; /** * The SAJAX library is loaded, lets initialize it */ sajax_init(); /** * Tell SAJAX which PHP functions to parse, in this case we have 1 i.e., checkMail() */ sajax_export("checkForm"); /** * Tell SAJAX to handle GET requests */ sajax_handle_client_request(); ?> <? echo("<?xml version=\"1.0\" encoding=\"utf-8\""."?>\n") ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link href="/css/generic.css" rel="stylesheet" type="text/css" /> <script language="JavaScript1.2" src="/script/validate.js" type="text/javascript"></script> <script language="JavaScript1.2" type="text/javascript"> <? sajax_show_javascript(); ?> function handleRequest(){ var email = document.getElementById('email').value; var password = document.getElementById('password').value; x_checkForm(email,password,handleResponse); } function handleResponse($array){ checkForm($array); } function checkForm($array){ var warning = ""; warning = "There has been a problem with your submission:\n\n"; warning_length = warning.length; /** * Email empty, in format, exist in dB? */ if(isEmpty('email')){ warning = warning + "- Email is missing\n"; }else if(isEmail('email')){ warning = warning + "- Email is not in a recognized format\n"; }else if(!$array[0]){ warning = warning + "- Email does not exist in our system\n"; } /** * Password empty? */ if(isEmpty('password')){ warning = warning + "- Password is missing\n"; } /** * Cannot authenticate Email & Password combination */ if(warning_length==warning.length){ if(!$array[1]){ warning = warning + "- Email and Password combination do not match our records\n"; } } /** * Display if any errors where generated */ if(warning_length!=warning.length){ alert(warning); }else{ document.forms[0].submit(); } } </script> </head> <body> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <div id="container"> <div id="container"> <span id="label">Email</span> <span id="field"><input id="email" name="email" title="Email" type="text" size="25" /></span> <span id="error">!</span> </div> <div id="container"> <span id="label">Password</span> <span id="field"><input id="password" name="password" title="Password" type="password" size="25" /></span> <span id="error">!</span> </div> <div id="container"> <span id="label">Forgotten your password? <a href="forgotten.php">Click here.</a></span> </div> <div id="container"> <span><input id="submit" name="submit" type="button" value="Submit" onclick="handleRequest();" /></span><span><input id="reset" name="reset" type="reset" value="Reset" /></span> </div> </div> </form> </body> </html>
document.forms[0].submit()
document.all.forms[0].submit()
document.<formname>.submit()
document.all.<formname>.submit()
* where <formname> is the name of the form in the name and/or id attribute.
Why oh why is this form not submitting? I know the script can see the form info as you can call
document.forms[0].action and get the action value.
BTW, the bit of code that is important here is:
Code:if(warning_length!=warning.length){ alert(warning); }else{ document.forms[0].submit(); }






Bookmarks