SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Contact form in WordPress

    Hello,

    I have a contact form script that I would like to use in my wordpress blog but doesn't seem to work correctly in wordpress. Is there anything special I have to do in the markup to get it working??

    Thanks!

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Is this a plugin, and if so, what plugin?

    Or, is this a completely customized script?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its a custom script. Not sure if I have to set the cantact page up diffrent. Any help would be great!

  4. #4
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    In that case, much more detail on the script and problem would be necessary. Relevant source code would also be helpful.

    What version of wordpress are you running?

    Was this script working before an upgrade and not after?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  5. #5
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres the whole file im trying to get to work:

    PHP Code:
    <?php
    /**
     * Template Name: Contact
     *
     *Contact Page Template
     *
     * The "Template Name:" bit above allows this to be selectable
     * from a dropdown menu on the edit page screen.
     *
     * @package WordPress
     * @subpackage The Aggressive Network
     * @since The Aggressive Network V1.0
     */
     
    ?>

    <?php
    if(isset($_POST['Submit_x'])) {
        
    $Your_Name htmlspecialchars($_POST['Name']);
        
    $email htmlspecialchars($_POST['Email']);
        
    $email2 htmlspecialchars($_POST['Email2']);
        
    $message htmlspecialchars($_POST['Message']);
        
    $security1 $_POST['security_code'];
        
    $security2 $_SESSION['security_code'];
        
    $subject htmlspecialchars($_POST['Subject']);
        
    $website htmlspecialchars($_POST['WebsiteURL']);
    if(
    $Your_Name == '') {
                
    $err true;
                
    $msg '! Please enter your name';}
            if (!
    eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$email) or $email == '') {
                
    $err4 true;
                
    $msg4 '! Please enter a valid email address';}
            if (!
    eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$email2) or $email2 == '') {
                
    $err8 true;
                
    $msg8 '! Please enter a valid email address';}
        list(
    $userName$mailDomain) = split("@"$email);
            if (
    $email2 !== $email) {
                 
    $err8 true;
                 
    $msg8 '! Email Addresses do not match';}
            if(
    $subject == 1) {
                
    $err6 true;
                
    $msg6 '! Please select subject';}
            if(
    $message == '') {
                
    $err5 true;
                
    $msg5 '! Please type a message';}
            if(
    $security1 == '') {
                
    $err3 true;
                
    $msg3 '! Please enter security code before trying to submit the form.';}
            if(
    $security2 != $security1) {
                
    $err2 true
                
    $msg2 '! Sorry, you have provided an invalid security code. Please try again.';
        } else { 
            if (
    eregi("\r",$email$email2) || eregi("\n",$email$email2)){ 
            die (
    "spam!");     
        } else {
                    if((
    $err == false) && ($err4 == false) && ($err8 == false) && ($err6 == false) && ($err5 == false) && ($err3 == false) && ($err2 == false) && ($err9 == false) && ($err10 == false)) {
                    
    $showForm false;                     
                    
    $mailmsg 'The following email has been sent from the Dragon Ink contact form:' "\n\n";
                    
    $mailmsg.= 'Name: ' $Your_Name "\n";
                    
    $mailmsg.= 'Email: ' $email "\n";
                    
    $mailmsg.= 'Website: ' $website "\n";
                    
    $mailmsg.= 'Subject: ' $subject "\n";
                    
    $mailmsg.= 'Message: ' $message "\n"
                    
    mail('support@theaggressive.com',$subject$mailmsg"From: Dragon-Ink"); 
                    unset(
    $_SESSION['security_code']);
                    
    $emailSent true;
                    
    $thy true;
                    
    $thymsg '<img src="contact/images/thankyou.jpg" width="188" height="33" alt="Thank You" border="0"><br />
    <p class="thy">Your message was sent: <span class="date">' 
    date("l, F j, Y @ g:ia") . '</span></p>';
                        }
    ?>

    <?php        
    get_header
    (); ?>

    <div id="main">
    <div id="left">
    <div class="left_Content"><div class="white_border">

    <h2>Contact Us</h2>
    <p>Want to get a hold of us? Feel free to offer any suggestions or if you have a question or a concern. Just simply fill out the form below. We will try our best to respond back to you as soon as we can.</p>

    <?php if($emailSent == true) { ?>

        <div class="thanks">
            <h1>Thanks!</h1>
            <p>Your email was successfully sent. I will be in touch soon.</p>
        </div>

    <?php } else { ?>

        <?php if (have_posts()) : ?>
        
        <?php while (have_posts()) : the_post(); ?>
            <h1><?php the_title(); ?></h1>
            <?php the_content(); ?>
                    
    <p class="news_dates">* Required Fields </p>

    <form action="<?php the_permalink(); ?>" method="POST" class="form">
    <div class="labelContainer"><label for="First_name"><span class="news_dates">*</span> Name:</label></div>
    <div class="fieldContainer"><input type="text" name="Name" id="Name" value="<?php echo $Your_Name?>" />

    <?php 
    if($err == true) {
                echo 
    '<p class="error">'$msg '</p>';
                }
    ?>

    </div>
    <div class="labelContainer"><label for="email"><span class="news_dates">*</span> Email:</label></div>
    <div class="fieldContainer"><input type="text" name="Email" id="Email" value="<?php echo $email?>" />

    <?php
    if($err4 == true) {
                echo 
    '<p class="error">'$msg4 '</p>';
                }
    if(
    $err7 == true) {
                echo 
    '<p class="error">'$msg7 '</p>';
                }
    ?>
    </div>
    <div class="labelContainer"><label for="email2"><span class="news_dates">*</span> Verify Email:</label>
    </div>
    <div class="fieldContainer"><input type="text" name="Email2" id="Email2" value="<?php echo $email2?>" />


    <?php
    if($err8 == true) {
                echo 
    '<p class="error">'$msg8 '</p>';
                }
    ?>

    </div>
    <div class="labelContainer"><label for="name">Your Site:</label></div>
    <div class="fieldContainer"><input name="WebsiteURL" type="text" id="WebsiteURL" value="http://www." /></div>
    <div class="labelContainer"><label for="subject"><span class="news_dates">*</span> Subject:</label></div>
    <div class="fieldContainer"><select name="Subject" size="1" id="Subject" class="Default_selectDropDown">
    <option value="1">------------Please Select------------</option>
    <option class="Selected_selectDropDown">Website Related</option>
    <option class="Selected_selectDropDown">Advertisement</option>
    <option class="Selected_selectDropDown">Articles Question or Comment</option>
    <option class="Selected_selectDropDown">Products</option>
    <option class="Selected_selectDropDown">Privacy Policy Question</option>
    <option class="Selected_selectDropDown">Other</option>
    </select>

    <?php
    if($err6 == true) {
                echo 
    '<p class="error">'$msg6 '</p>';
                }
    ?>

    </div>
    <div class="labelContainer"><label for="message"><span class="news_dates">*</span> Message:</label></div>
    <div class="fieldContainer"><textarea rows="8" cols="60" name="Message" id="Message" ><?php echo $message?></textarea>

    <?php 
    if($err5 == true) {
                echo 
    '<p class="error">'$msg5 '</p>';
                }
    ?>

    </div>
    <div class="mailing_check"><input name="mailing" type="checkbox" id="mailing" value="true"> Add me to your mailing list!</div>
    <div class="codelabelContainer"><label for="code"><span class="news_dates">*</span> Code:</label></div>
    <div class="captcha"><img src="<?php bloginfo('template_directory'); ?>/contact/CaptchaSecurityImages.php?width=120&height=40&characters=5" alt="Image Code" style="border: 1px solid #666; "/></div>
    <div class="labelContainer"><label for="security_code"><span class="news_dates">*</span> Enter Code:</label></div>
    <div class="fieldContainer"><input name="security_code" type="text" id="security_code" value="Enter above code here" onFocus="if(this.value=='Enter above code here')this.value='';" />

    <?php
    if($err2 == true) {
                echo 
    '<p class="error">'$msg2 '</p>';
                }
    if(
    $err3 == true) {
                echo 
    '<p class="error">'$msg3 '</p>';
                }
    ?>

    </div>
    <div class="submit"><input name="Submit" type="submit" value="Submit" alt="Submit" /></div>
    </form>    
            <?php endwhile; ?>
        <?php endif; ?>
    <?php 
    }                }
                }
            }
     
    ?>

    </div><!-- white_border --></div><!-- left_Content -->
    </div><!-- left -->
    <?php include(TEMPLATEPATH '/sidebar1.php'); ?>
    </div><!-- main -->
    </div><!-- close wrap -->
    </div><!-- bg_top_grad -->
    <?php get_footer(); ?>
    ALSO i dont know why my captcha images isnt showing. i placed it in my themes folder named contact. it was working before trying to use it on this wordpress blog.

  6. #6
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Chameleon View Post
    I have a contact form script that I would like to use in my wordpress blog but doesn't seem to work correctly in wordpress.
    What isn't working exactly? Do you see any error messages? (use PHP: error_reporting - Manual to enable error reporting, so long as it isn't turned off at the server level)

    Code:
    error_reporting(E_ALL);
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  7. #7
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get the following:

    Notice: Undefined variable: emailSent in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 86

    Notice: Undefined variable: err in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 108

    Notice: Undefined variable: err4 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 118

    Notice: Undefined variable: err7 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 121

    Notice: Undefined variable: err8 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 132

    Notice: Undefined variable: err6 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 152

    Notice: Undefined variable: err5 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 162

    Notice: Undefined variable: err2 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 175

    Notice: Undefined variable: err3 in /home/content/D/r/a/Dragon60154739/html/wp-content/themes/Aggressive/contact.php on line 178

  8. #8
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok well, the script isnt showing the errors or sending the email if all fields are filled out right..... any idea?

  9. #9
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    None of the variables within your if-statement are available where you try to access them in your HTML.

    If you want to use variables that are within in your if-statement, you will need to define them outside in order to have access to them

    For example, this is what your code is doing:
    Code PHP:
    <?php
    if($something==true){
        $thing=true;
    }
    ?>
     
    <html><body>
        <?php if($thing==true){?><p>Thing is true!</p><?php } ?>
    </body></html>

    This would throw an error because the $thing variable isn't accessible from inside the if-statement.

    This is how you should write it to have access to the $thing variable outside of the if-statement:
    Code PHP:
    <?php
     
    $thing=false;
     
    if($something==true){
        $thing=true;
    }
    ?>
     
    <html><body>
        <?php if($thing==true){?><p>Thing is true!</p><?php } ?>
    </body></html>


    [edit]: nevermind, I had forgotten that PHP doesn't have its own scope for if-statements, so while this isn't technically valid for PHP, it's still good to put into practice to ensure good, clean, bug-free code.
    Last edited by Force Flow; Mar 21, 2011 at 19:44.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  10. #10
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all of the help!

    the problem was this

    PHP Code:
    <?php if(isset($_POST['Submit_x'])) {
    had to change it to this:

    PHP Code:
    <?php if(isset($_POST['Submit'])) {


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •