Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    submit form problem

    Wasn't sure where to post this as i am not sure what's causing the problem...

    I have an HTML form that validates with an onSubmit for javascript validation followed by and action:... which submits the the form into a database using php. at first the form submitted no problem but now that i put the js in the action doesn't seem to run.

    Do these usually clash? Do I have to do both with the same language?

    The javascript is and external file, in case that changes anything.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    ??? You can't use JavaScript in the action="..." attribute. You can ONLY specify the TEXT name of the target page.

    If that's not what you meant that you did, show us your actual code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post
    sorry about that. What I was tryin to explain is in the action=" ", I call php and call javascript in the onSubmit in the same form:

    PHP Code:
    <form name="client_add" method="post" onsubmit="return validateForm();" action="client_save.php">
                        <
    label>First Name</label><br />
                            <
    input type="text" name="first_name" /><br />
                        <
    label>Last name</label><br />
                            <
    input type="text" name="last_name" /><br />
                        <
    label>Password</label><br />
                            <
    input type="password" name="password" /><br />
                        <
    label>Confirm Password</label><br />
                            <
    input type="password" name="confirm_password" /><br />    
                        <
    label>Phone Number</label><br />
                            <
    input type="text" name="phone_number" /><br />
                        <
    label>Email</label><br />
                            <
    input type="text" name="email" /><br />
                    <
    input type="submit" value="save" />
                </
    form
    I didn't post code because I wasn't sure exactly what code would be most useful.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    That looks right, except that you gave a name to the <form>, which is obsolete.

    Now go look in the other thread, where I commented on how you could/should validate.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Aug 2012
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post
    edited
    Last edited by Vigilante23; 10-03-2012 at 04:22 AM.

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    along with all the other advice that you haven't followed, your brackets are still screwed up.

    Code:
    function validateForm() {
    	var fName = document.forms["client_add"]["first_name"].value;
    	var password = document.forms["client_add"]["password"].value;
    	var confirmPassword = document.forms["client_add"]["confirm_password"].value;
    	var phoneNumber = document.forms["client_add"]["phone_number"].value;
    	var email = document.forms["client_add"]["email"].value;
    	var x=document.forms["client_add"]["email"].value;
    	var atpos=x.indexOf("@");
    	var dotpos=x.lastIndexOf(".");
    	if (fName==null || fName==="") {
    		alert ("You must enter a name");
    		return false;
    	}
    	if (password==null || password==="") {
    		alert ("You must enter a password");
    		return false;
    	}
    	if (password!=confirmPassword) {
    		alert ("Passwords do not match");
    		return false;
    	}
    	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
    	  alert("Not a valid e-mail address");
    	  return false;
    	}
    }


  •  

    Posting Permissions

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