• My custom contact form page used to work, but for some reason, it results in a 404 error when I submit my form. I am using custom permalinks (/%category%/%postname%/) and that has never been a problem before.

    I started off with WordPress 3.0 and I have updated the WordPress a few times and was wondering if any of those updates could have caused this. If not, what would? I’m still working on my theme, but I haven’t touched my contact page template for a long time (I separated it from the other pages).

    if(isset($_POST['submitted'])) {
    	if(trim($_POST['subject']) === '') {
    		$subject = 'No subject';
    	} else {
    		$subject = trim($_POST['subject']);
    	}
    	if(trim($_POST['author']) === '') {
    		$authorError = 'A valid name is required.';
    		$hasError = true;
    	} else {
    		$author = trim($_POST['author']);
    	}
    	if(trim($_POST['email']) === '')  {
    		$emailError = 'A valid email address is required.';
    		$hasError = true;
    	} else if (!preg_match("/^((([a-z]|\d|[!#$%&\'*+\-\/=?\^_<code>{|}~]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])+(\.([a-z]|\d|[!#$%&\'*+\-\/=?\^_</code>{|}~]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])|(\\\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])|(([a-z]|\d|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])([a-z]|\d|-|\.|_|~|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])*([a-z]|\d|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])))\.)+(([a-z]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])|(([a-z]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])([a-z]|\d|-|\.|_|~|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])*([a-z]|[\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}])))\.?$/iu", trim($_POST['email']))) {
    		$emailError = 'A valid email address is required.';
    		$hasError = true;
    	} else {
    		$email = trim($_POST['email']);
    	}
    	if(trim($_POST['message']) === '') {
    		$messageError = 'A message is required.';
    		$hasError = true;
    	} else {
    		if(function_exists('stripslashes')) {
    			$message = stripslashes(trim($_POST['message']));
    		} else {
    			$message = trim($_POST['message']);
    		}
    	}
    	if(!isset($hasError)) {
    		$emailTo = get_option('admin_email');
    		$subject_send = '[ from website ] '.$subject;
    		$body = "$message";
    		$headers = 'From: '.$author.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;
    		mail($emailTo, $subject_send, $body, $headers);
    		$emailSent = true;
    	}
    	$errorClass = ' class="error"';
    }
    <form action="<?php the_permalink(); ?>" id="feedbackform" method="post" novalidate>
    	<p>
    		<label for="author">Name</label>
    		<?php if($authorError != '') { ?><label class="error" for="author"><?=$authorError;?></label>
    		<?php } ?><input id="author" name="author" type="text" value="<?php if(isset($hasError)) echo $_POST['author'];?>" title="Your name is required"<?php if($authorError != '') { echo $errorClass; } ?> />
    	</p>
    	<p>
    		<label for="email">Email</label>
    		<?php if($emailError != '') { ?><label class="error" for="email"><?=$emailError;?></label>
    		<?php } ?><input id="email" name="email" type="email" value="<?php if(isset($hasError)) echo $_POST['email'];?>" title="Your email address is required"<?php if($emailError != '') { echo $errorClass; } ?> />
    	</p>
    	<p>
    		<label for="subject">Subject</label>
    		<input id="subject" name="subject" type="text" value="<?php if(isset($hasError)) echo $_POST['subject'];?>" title="The subject is optional" />
    	</p>
    	<p>
    		<label for="message">Message</label>
    		<?php if($messageError != '') { ?><label class="error" for="message"><?=$messageError;?></label>
    		<?php } ?><textarea id="message" name="message" title="Your message is required"<?php if($messageError != '') { echo $errorClass; } ?>><?php if(isset($hasError)) { if(function_exists('stripslashes')) { echo stripslashes($_POST['message']); } else { echo $_POST['message']; } } ?></textarea>
    	</p>
    	<p>
    		<input id="submit" name="submit" type="submit" value="Send Message" />
    		<input type="hidden" name="submitted" id="submitted" value="true" />
    	</p><?php if(isset($emailSent) && $emailSent == true) { ?>
    	<p>Your message has been sent. I will reply as soon as possile.</p><?php } ?>
    </form>
  • The topic ‘custom contact form no longer working’ is closed to new replies.