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'}" />
<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'}"/>
<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>