Support » Themes and Templates » simple form post problem

  • First time creating a theme from scratch.

    I’ve built a form (simple one):

    <form name="cform" method="post" action="<?php echo bloginfo('template_directory') . '/contact-form.php' ?>">
      <input id="cname" name="cname" type="text" value="Name" />
      <input id="cemail" name="cemail" type="text" value="Email" />
      <input id="cphone" name="cphone" type="text" value="Phone" />
      <textarea id="cmessage" name="cmessage" rows="6" cols="33">Message</textarea>
      <button id="submit" type="submit" name="submit">Send</button>

    PHP I’m using to process the form:

    if(isset($_POST['submit'])) {
    $to = "";
    $subject = "Capital Care Contact Form";
    $name_input = $_POST['cname'];
    $email_input = $_POST['cemail'];
    $phone_input = $_POST['cphone'];
    $message = $_POST['cmessage'];
    $body = "From: $name_input\n E-Mail: $email_input\n Phone: $phone_input\n Message:\n $message";
    echo "Data has been submitted to $to!";
    mail($to, $subject, $body);
    } else {
    echo "blarg!";

    I don’t know why but when I submit a test form I get a 404 the page cannot be found error.

    Any ideas why WordPress thinks the file is missing?


Viewing 5 replies - 1 through 5 (of 5 total)
  • Is there a security feature in WordPress that doesn’t allow access to files in the template directory?

    Or maybe the mod rewrite rules wordpress writes is causing the 404.

    I searched for hours and this must be a simple fix.

    Thanks in advance!

    So I created a test.html page in my template root. In contact.php (a custom template page) I inserted a anchor link to test test.html:
    <a href="<?php echo bloginfo('template_url') . '/test.html' ?>"> test</a>

    It opens and renders just fine. So why do I get a 404 when I do the same for a php file I create. Surly there is a way to create your own php files and link to them from other php files.

    I’ve obviously over estimated this problem. I looked and searched and searched, every few months some one posts a problem like this, and no one replys.

    Maybe WP 3.0 will allow you to link to other php files in your template root

    Turns out it is a .htaccess issue. I guess wordpress is writing some rules that restricts putting static pages into theme directory. I put the contact-form.php in the site root rather then template root.

    I’m getting the same issue. with using a custom template/ page.

    works fine when I don’t use anything within the form (error works fine)
    but when theres something within the form it 404s 🙁

    will follow your guidance with the site root but need to now work out how to theme a root file :/

    sorry for mega bump

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘simple form post problem’ is closed to new replies.