SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Form won't submit

    Can't get form to submit but validation works... Even once the validation is accepted the form still will not submit.

    Code HTML4Strict:
    <form class="contact" method="post" action="contact.php" name="contact" onsubmit="return messagesend()">

    Code JavaScript:
    messagesend.onclick = function(){
    		if (fullnameform == null || fullnameform =="" || emailform == null || emailform =="" || subjectform == null || subjectform =="" || bodyform == null || bodyform =="")
    		  {
    		  	if (fullname.value.length === 0){
    		  		show_error(fullname_msg, 'This field is required.');
    		  		messagesend.disabled = true;
    		  	}else if (fullname.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(fullname_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(fullname_msg);
    		  	}
     
    		  	if (email.value.length === 0){
    		  		show_error(email_msg, 'This field is required.');
    		  	}else if (email.value.match(/^[a-z0-9\-\.\_\+]{1,64}\@(?:[a-z0-9\-\_]+)\.(?:[a-z]{2,4}|[a-z]{2,3}\.[a-z]{2,3})$/) === null){
    		  		show_error(email_msg, 'Invalid e-mail address.');
    		  	}else{
    		  		removeChildren(email_msg);
    		  	}
     
    		  	if (subject.value.length === 0){
    		  		show_error(subject_msg, 'This field is required.');
    		  	}else if (subject.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(subject_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(subject_msg);
    		  	}
     
    		  	if (body.value.length === 0){
    		  		show_error(body_msg, 'This field is required.');
    		  	}else if (body.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(body_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(body_msg);
    		  	}	
     
    		  	return false;
    		  }
    	}

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kammel View Post
    messagesend() needs to return a value of true for the form to be submitted.
    I populate all of the fields with data. This doesn't seem to work by having return true.

    Code JavaScript:
    messagesend.onclick = function(){
    		if (fullnameform === null || fullnameform ==="" || emailform === null || emailform ==="" || subjectform === null || subjectform ==="" || bodyform === null || bodyform ==="")
    		  {
    		  	if (fullname.value.length === 0){
    		  		show_error(fullname_msg, 'This field is required.');
    		  		messagesend.disabled = true;
    		  	}else if (fullname.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(fullname_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(fullname_msg);
    		  	}
     
    		  	if (email.value.length === 0){
    		  		show_error(email_msg, 'This field is required.');
    		  	}else if (email.value.match(/^[a-z0-9\-\.\_\+]{1,64}\@(?:[a-z0-9\-\_]+)\.(?:[a-z]{2,4}|[a-z]{2,3}\.[a-z]{2,3})$/) === null){
    		  		show_error(email_msg, 'Invalid e-mail address.');
    		  	}else{
    		  		removeChildren(email_msg);
    		  	}
     
    		  	if (subject.value.length === 0){
    		  		show_error(subject_msg, 'This field is required.');
    		  	}else if (subject.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(subject_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(subject_msg);
    		  	}
     
    		  	if (body.value.length === 0){
    		  		show_error(body_msg, 'This field is required.');
    		  	}else if (body.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(body_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(body_msg);
    		  	}	
     
    		  	return false;
    		  }
    		return true;
    	}

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kammel View Post
    Have you gone through and debugged each section of your code using alert()s or browser development tools to find the errors or do you want someone to do it for you?

    Even if alert() is the only debugging tool you have access to, it should take only a few minutes to move an alert() progressively down your code to find the line of code causing any problems.
    I went through and put in the alerts like you suggested. It appears that my alert will only display once if I click on the submit button. I believe that every time I hit the submit button my alert should launch, right? See sample code below.

    Code JavaScript:
    messagesend.onclick = function(){
    		if (fullnameform === null || fullnameform ==="" || emailform === null || emailform ==="" || subjectform === null || subjectform ==="" || bodyform === null || bodyform ==="")
    		  {
    		  	if (fullname.value.length === 0){
    		  		alert('wrong');
    		  		show_error(fullname_msg, 'This field is required.');
    		  		messagesend.disabled = true;
    		  	}else if (fullname.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(fullname_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(fullname_msg);
    		  	}
     
    		  	if (email.value.length === 0){
    		  		show_error(email_msg, 'This field is required.');
    		  	}else if (email.value.match(/^[a-z0-9\-\.\_\+]{1,64}\@(?:[a-z0-9\-\_]+)\.(?:[a-z]{2,4}|[a-z]{2,3}\.[a-z]{2,3})$/) === null){
    		  		show_error(email_msg, 'Invalid e-mail address.');
    		  	}else{
    		  		removeChildren(email_msg);
    		  	}
     
    		  	if (subject.value.length === 0){
    		  		show_error(subject_msg, 'This field is required.');
    		  	}else if (subject.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(subject_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(subject_msg);
    		  	}
     
    		  	if (body.value.length === 0){
    		  		show_error(body_msg, 'This field is required.');
    		  	}else if (body.value.match(/^[a-zA-Z]+$/) === null){
    		  		show_error(body_msg, 'Invalid name (letters only).');
    		  	}else{
    		  		removeChildren(body_msg);
    		  	}	
     
    		  	return false;
    		  }
    	}

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    messagesend.onclick = function(){
    This assigns an anonymous function to the onclick handler of messagesend, which doesn't appear to be an element.

    You probably meant
    Code:
    function messagesend(){ ...
    Use the error console.
    Tab-indentation is a crime against humanity.


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
  •