• Resolved joshuagatcke

    (@joshuagatcke)


    Hello All,

    I am working on a contact form plugin (yes I know there are several good plugins already), https://www.editedoutbyrequest.com/v2/contact-us/ (might not be safe for work but is not adult or offensive). The problem I am having, is that whenever I submit the form, it seems like wordpress drops all its page information. Even though the url is correct, wordpress doesn’t know what page we are viewing. If you have a chance, please view the url and submit the form, you will see what I am saying.

    Here is the plugin code (work in progress). I have stripped out anything that is not essential to the form submitting.

    Thanks in advance for any help, this is driving me nuts.


    <?php
    /*
    Plugin Name: jpg_contact
    Plugin URI:
    Description: A Secure Plugin Contact Form
    Author: Joshua Gatcke
    Version: 1.0
    Author URI: https://www.editedoutbyrequest.com
    */
    ?>
    <?php
    //make the magic happen ;)
    function jpg_contact($content){
    //if there is not contact form tag, return the content
    if(! preg_match('|<!--JPG_CONTACT-->|', $content)){
    return $content;
    }else{
    //check for hidden post variable from our form
    if(isset($_POST['jpg_contact'])){

    //Process the form
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $email2 = $_POST['email2'];
    $comments = $_POST['comments'];
    $recipient = "[email protected]";
    $subject = "JPG Contact Form Results";

    $headers = "From: $name <$email>n";
    $headers .= "X-Sender: [email protected]";
    $headers .= "X-Mailer: PHPn"; //mailer;
    $headers .= "X-Priority: 3n"; //1 UrgentMessage, 3 Normal;
    $headers .= "Return-Path: $emailn";

    $the_message = "Name: ".$name."n";
    $the_message .= "Phone: ".$phone."n";
    $the_message .= "E-mail: ".$email."n";
    $the_message .= "Name: ".$name."n";
    $the_message .= "Comments: ".wordwrap($comments, 80, "n");

    //send the form
    if (mail( $recipient, $the_subject, $the_message, $headers)){
    $jpg_success = 'yes';
    }else{
    print ("could not send mail");
    }//end if mailed
    }/*end if jpg_contact*/

    if(!$jpg_success){
    //if there is a contact form tag, show the contact form
    $jpg_form = '<form action="'.get_permalink().'" method="get" name="contact_form">';
    $jpg_form .= '<div id="jpg_contact">';
    $jpg_form .= '<lable>Name:</lable>';
    $jpg_form .= '<input type="text" value="" name="name" />';
    $jpg_form .= '<lable>Phone Number:</lable>';
    $jpg_form .= '<input type="text" value="" name="phone" />';
    $jpg_form .= '<lable>E-mail Address:</lable>';
    $jpg_form .= '<input type="text" value="" name="email" />';
    $jpg_form .= '<lable>Confirm E-mail Address:</lable>';
    $jpg_form .= '<input type="text" value="" name="email2" />';
    $jpg_form .= '<lable>Questions/Comments:</lable>';
    $jpg_form .= '<textarea cols="40" rows="10" name="comments"></textarea>';
    $jpg_form .= '<input type="hidden" value="true" name="jpg_contact" />';
    $jpg_form .= '<input type="submit" value="Send Message" name="submit" />';
    $jpg_form .= '</div></form>';
    }else if($jpg_success){
    $jpg_form = 'You Rock :)';
    }else{
    $jpg_form = "nothing here";
    }

    $content = str_replace("<!--JPG_CONTACT-->", $jpg_form, $content);
    return $content;
    }
    }

    //add the contact form css file to the head
    function jpg_contact_css(){?>
    <link rel="stylesheet" type="text/css" href="contact_form.css" media="all" />
    <?php }/*end jpg_contact_css*/

    //register the plugin sink(s) Filters & Actions
    add_filter('the_content', 'jpg_contact');
    add_filter('wp_head','jpg_contact_css');
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter joshuagatcke

    (@joshuagatcke)

    I also wanted to note that I have indeed read the codex page about self submitting scripts to no avail. Thanks.

    Thread Starter joshuagatcke

    (@joshuagatcke)

    ok, even if I make the form 1 field with a submit button it still doesn’t work. I have tried disabling the custom permalinks as well, I thought maybe the mod re-write rules might have been messed but it didn’t help.

    I have seen lots of other plugins using self submitting forms, not sure why I cannot get it to work.

    Thread Starter joshuagatcke

    (@joshuagatcke)

    Seems to be working now. Not sure why. I just left it alone for a while, then came back and tried it again and it worked.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘self-submitting plugin’ is closed to new replies.