0

Been trying to ask on Wordpress forums, but no hits. I'm hoping there are more people here that can help me.

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|[!#$%&\'*+\-\/=?\^_`{|}~]|[\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}])+)*)|((\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"';
}

and...

<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>
4
  • could be the field names, try adding a prefix change author to c_author , email to c_email , subject to c_subject and message to c_message
    – Bainternet
    Commented Jul 30, 2011 at 12:59
  • Okay, it works. So, before I was complaining that they prevented me from using "Name" for the name field and I had to resort to using "Author" instead. Now they completely prevented me from using any standardized naming. Say goodbye to browser form history or is there a way around this?
    – gavsiu
    Commented Jul 30, 2011 at 14:14
  • Its the same as before, you can't use saved keywords
    – Bainternet
    Commented Jul 30, 2011 at 16:31
  • The form did work before 3.2. That's why the contact page was supposed to be finished.
    – gavsiu
    Commented Jul 30, 2011 at 19:00

1 Answer 1

0

As suggested by Bainternet, prefix all the field names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.