I have a form at the bottom my website's homepage. I was wondering if there was a way, when you clicked the submit button, especially if there were errors with the form, to send you directly to the bottom of the page with either, javascript, php, or html. The code is not fully finished (esp the form validation)

<?php
       	       if(!isset($_POST['submit'])) {
       	       
       	       $name = "Name";
       	       }
       	       ?>
       	       <td class="form">
       	       <?php
           	   
           	   	 if (isset($_POST['submit'])) {
           	   	 
           	   	 $error = '';
           	   	 
           	   	 if(trim($_POST['Name'] == '')) {
           	   	 	$error .="Please enter a name.</br>";}
           	   	 	
           	   	 if($error == '') {
           	   	            	   	 
           	   	 $name = $_POST['Name'];
           	     $email = $_POST['Email'];
           	     $company = $_POST['Company'];
           	     $city = $_POST['City'];
           	     $message = $_POST['Message'];
           	     
				 $headers = "$name\n $email\n $company\n $city\n";
           	     
           	     mail('a****@s**************.n**', 'form', $message, $headers);
           	     
           	     echo 'Your form has been submitted.';
           	       }
           	       
           	       else {
           	       
           	       $name = 'Name';
           	       
           	       	echo $error;
           	       	}
           	     }
           	   ?>
     	       
       	       <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
       		    <input name="Name" type="text" class="textfield"
       		  	 value="<?php echo $name; ?>" 
       		  	 	 onfocus="if (this.value == 'Name') {this.value=''}"
		      	 	 onblur="if (this.value == '') {this.value='Name'}" />&nbsp; &nbsp; 
		      <input name="Email" type="text" class="textfield"
		      	 value="E-mail" 
		      	 	 onfocus="if (this.value == 'E-mail') {this.value=''}"
		      	 	 onblur="if (this.value == '') {this.value='E-mail'}"/><br/><br/>
              <input name="Company" type="text" class="textfield"
              	 value="Company" 
              	 	 onfocus="if (this.value == 'Company') {this.value=''}"
		      	 	 onblur="if (this.value == '') {this.value='Company'}"/>&nbsp; &nbsp; 
		      <input name="City" id="City" type="text" class="textfield"
		      	 value="City (only for quote)"
		      	 	 onfocus="if (this.value == 'City (only for quote)') {this.value=''}"
		      	 	 onblur="if (this.value == '') {this.value='City (only for quote)'}" /><br/><br/>
              <textarea name="Message" id="Message" rows="4" class="textarea"
              		 onfocus="if (this.value == 'Message/Project Description') {this.value=''}"
              		 onblur="if (this.value == '') {this.value='Message/Project Description'}"
              >Message/Project Description</textarea><br/><br/>
           	  <input name="submit" type="image" src="Home/Form/Send.png" value="submit"
           	  		 onclick="clearFields() "/>
           	 </form>

I have a form at the bottom my website's homepage. I was wondering if there was a way, when you clicked the submit button, especially if there were errors with the form, to send you directly to the bottom of the page with either, javascript, php, or html. The code is not fully finished (esp the form validation)

Using JavaScript, you can check the form before the user leaves the page with an "onsubmit" call in the <form> tag. This way if there are errors with the form, the user is notified before he/she actually submits the form.

Ask here: http://www.daniweb.com/forums/forum117.html
I'm sure someone there can help you further.


Alternatively, if you want to send the user to the bottom of the page upon submitting the form(regardless of circumstances), you can create an html anchor and add it to the form submit link. Example:

<a name="page_bottom" /> <!--Put at bottom of page near form-->
<form action="<?php echo $_SERVER['PHP_SELF'] . "#page_bottom"; ?>" >
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.