SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Read the posts, cannot find a solution: submit();

    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:

    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>
    I have tried various methods including:

    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();
    			}
    Last edited by affordablemagic; Feb 20, 2007 at 18:52. Reason: Further explanation

  2. #2
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up The answer, makes no sense, but the answer.

    The funny part is, it's always after you post for help that you figure it all out. It doesn't matter whether you spent an hour before hand trying to figure out the answer or 12.

    This is why the request:

    Code:
    document.forms[0].submit();
    Didn't work. It is because my page contained a submit button with the name attribute set to 'submit':

    Code:
    <input id="submit" name="submit" type="submit" value="Submit" />
    It turns out that if you have a form element with a name attribute of submit, the command document.forms[0].submit() just refers to that object, not to the command submit(). The solution, change the form elements name: attribute:

    Code:
    <input id="commit" name="commit" type="submit" value="Submit" />

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Congratulations on figuring it out yourself.

    This is a rather common problem.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Thanks! ;)

    But why? I mean, it doesn't make sense to me. A call to:

    resource

    vs

    resource()

    are clearly different.

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To take your example, resource is a reference to a function and resource() is a call to that function. They must both be the same function. Hence, when you make a new variable within the same scope (after the function was declared) that has the same name as the function, you can no longer access the function.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •