Grow your CSS skills. Land your dream job.

WordPress self referencing form

  • # September 17, 2010 at 5:59 pm

    Hi, I am trying to create a self referencing contact form in wordpress but I can’t work out what to put in the post-action bit. I have tried everything I can think of like

    <form action="<?php bloginfo('url')?>/contact-php

    and things but everything comes back to page net found, what am I missing?

    Bob
    # September 18, 2010 at 1:49 pm

    Are you sure the page exists? Also, you need to have permalinks set up and working, cause this is a permalink you’re referring to. The way you do it now, the output would be:

    http://example.com/contact-php

    But if you don’t have permalinks set up, it won’t work. Check whether or not they are set up and see if this page really exists. Otherwise, try referencing it to some page you do know exists for sure, and add the extension to it, like this:

    http://example.com/about.php

    Or like

    <?php bloginfo('url')?>/about.php

    # September 20, 2010 at 1:41 pm

    The page defiantly exists, on the permalinks section in the pages it is ‘/contact-php’ and when I go to the page directly it goes there
    Cheers,
    Matt

    Bob
    # September 20, 2010 at 3:35 pm

    Can you please post your full code of the form? There might an error in your code, as I’ve just tried it with the following code, which works just fine:

    <form action="<?php bloginfo('url')?>/?page_id=2"><br />
    <input type="submit" /><br />
    </form>
    <code></code>

    In the code you submitted in your first post, there is no ” at the end, maybe thats why it doesn’t work? Anyway, like I said, post your full code so we can see whats going on.

    # September 20, 2010 at 3:50 pm

    Here is the code:

    if(isset($_POST)){<br />
    $emailFrom = strip_tags($_POST);<br />
    $emailTo = "matt@digital-spoon.co.uk";<br />
    $subject = "Contact Form Submission";<br />
    <br />
    $name = strip_tags($_POST);<br />
    $city = strip_tags($_POST);<br />
    $email = strip_tags($_POST);<br />
    $message = strip_tags(stripslashes($_POST));<br />
    <br />
    $body = "Name: ".$name."n";<br />
    $body .= "City: ".$city."n";<br />
    $body .= "Email: ".$email."n";<br />
    $body .= "Message: ".$message."n";<br />
    <br />
    $headers = "From: ".$emailFrom."n";<br />
    $headers .= "Reply-To:".$email."n";<br />
    <br />
    if(isset($_POST)){<br />
    $success = mail($emailTo, $subject, $body, $headers);<br />
    if ($success){<br />
    echo '<p class="yay">All is well, your e&ndash;mail has been sent.</p>';<br />
    }<br />
    } else {<br />
    echo '<p class="oops">Something went wrong</p>';<br />
    }<br />
    } else {<br />
    ?><br />
    <br />
    <form action="<?php bloginfo('url'); ?>/contact-php/" method="post" id="contact" name="contact"><br />
    <fieldset><br />
    <legend>Contact form</legend><br />
    <label for="name">Name</label><br />
    <input type="text" id="name" name="name" class="required" minlength="2"/><br />
    <br />
    <label for="city">City</label><br />
    <input type="text" id="city" name="city" class="required" minlength="2"/><br />
    <br />
    <label for="email">E&ndash;mail</label><br />
    <input type="text" id="email" name="email" class="required email"/><br />
    <br />
    <label for="message">Message</label><br />
    <textarea id="message" name="message" cols="50" rows="10" class="required"></textarea><br />
    <br />
    <br />
    <input type="submit" id="submit" name="submit" value="Send!" /><br />
    </fieldset><br />
    </form>
    <code></code>

    Cheers,
    Matt

    Bob
    # September 20, 2010 at 4:22 pm

    I can’t really see an error there, do you have a live example?

    Also, try testing it locally with MAMP or something like that, to see if that works. Might be something with your hosting.

    # September 20, 2010 at 5:04 pm

    http://www.digital-spoon.co.uk/contact-php/ is the site where I am testing on,
    Cheers,
    Matt

    # September 23, 2010 at 6:05 am

    Have you tried just using:

    # January 5, 2013 at 6:10 pm

    In case anyone finds this via search…

    I encountered the same issue, and it has to do with the form field names. I believe WordPress is interpereting either a POST or GET key value of ‘name’ as a post name to determine what wordpress page to show (resulting in a 404 error in most cases).

    To verify if this is the issue, put in the slug of a post (like ‘contact-php’) in the name field, submit the form and see what happens (If it is a valid page/post slug, it should take you to that page).

    Laters,
    Stephen

    # May 6, 2013 at 4:12 pm

    @sspann Thanks! That was my issue. I should know better than to use common variable names by now.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".