WordPress.org

Ready to get started?Download WordPress

Forums

simple form post problem (6 posts)

  1. osura
    Member
    Posted 4 years ago #

    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' ?>">
    
    <fieldset>
      <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>
    </fieldset>
    
    </form>

    PHP I'm using to process the form:

    <?php
    if(isset($_POST['submit'])) {
    $to = "myemail@gmail.com";
    $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?

    Thanks.

  2. osura
    Member
    Posted 4 years ago #

    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!

  3. osura
    Member
    Posted 4 years ago #

    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.

  4. osura
    Member
    Posted 4 years ago #

    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

  5. osura
    Member
    Posted 4 years ago #

    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.

  6. Trevsweb
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic