Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress self referencing form

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #30280
    matt25
    Participant

    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?

    #79546
    Bob
    Member

    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

    #79582
    matt25
    Participant

    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

    #79586
    Bob
    Member

    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.

    #79588
    matt25
    Participant

    Here is the code:

    if(isset($_POST)){<br />
    $emailFrom = strip_tags($_POST);<br />
    $emailTo = "[email protected]";<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

    #79590
    Bob
    Member

    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.

    #79591
    matt25
    Participant

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

    #79214
    willB
    Member

    Have you tried just using:

    #119936
    sspann
    Member

    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

    #134280
    FurySting
    Member

    @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)
  • The forum ‘Back End’ is closed to new topics and replies.