Results 1 to 6 of 6

Thread: Wordpress Tip #320 (not really) Using the comments section for a contact form.

  1. #1
    @haroldmansfield Array Harold Mansfield's Avatar
    Join Date
    Aug 2008
    Location
    Las Vegas Nevada USA
    Posts
    6,171

    Default Wordpress Tip #320 (not really) Using the comments section for a contact form.

    This is an oldie but a goodie.
    Many times when you use WP as a static or informational website, you may disable the comments so as not to have that big comment box sitting below your posts or pages when you really aren't looking for comments.

    The comments section has everything that a standard contact form has:
    A field for "Name", "Email", "Website", and a box for additional comments..so why not use it ?

    You can use it as a mini contact form that is visible below all of the content that you choose.

    This takes just a little editing of the "comments.php" file of your theme.

    First you want to look for the line of code that is the title (what makes it say "Comments"), it should look like, or similar to this:

    <h3><?php comment_form_title( 'Comments', 'Comment &#37;s' ); ?></h3>
    Just change 'Comments' to "Contact Me" or what ever you want it to say.

    You can leave the input fields the same, they will probably look something like this:


    <?php else : ?>

    [I]<p><input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
    <label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>

    <p><input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
    <label for="email"><small>E-Mail <?php if ($req) echo "(required)"; ?></small></label></p>

    <p><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
    <label for="url"><small>Website (if Applicable)</small></label></p>

    <?php endif; ?>
    But you probably want to change the Submit Comment button. Look for this code a little further down:
    <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
    <?php comment_id_fields(); ?>
    and change "Submit Comment" (or whatever it says) to "Send" or what ever you want it to say...and save.

    Now from your Dashboard ->Settings ->Discussion, set your comments to "Any User can comment" and "Comments Must be approved by Moderator", and that should do it.

    Now you have a mini contact form that you can opt to display at the bottom of any page or post that should look like this (in the post/page options), and you can see if you have any action from it in your dashboard the way you would normally see any comments left.
    Last edited by Harold Mansfield; 10-28-2009 at 02:59 AM.
    Small Business Web Consultant
    1:1 Web Help for Start Ups, Novices, and DIY’ers

    WordPress Website Design » WordPress Support

  2. #2
    Post Impressionist Array vangogh's Avatar
    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    13,539

    Default

    Interesting idea. I suppose it can mess up regular commenting, though not that much and it's probably not a big deal if you prefer the contact form anyway.

    I've been using a plugin called Contact Form 7 lately and it's really nice. Very easy to use. It creates a shortcode you can drop into any post or page and you have a contact form.

    On my site I just coded up the contact form and dropped it into the sidebar. It's easy enough for me to do anyway. The idea of letting them all come through WordPress is interesting though.
    l Search Engine Friendly Web Design | Vanseo Design
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Custom WordPress Themes |Get my book about Design Fundamentals

  3. #3
    @haroldmansfield Array Harold Mansfield's Avatar
    Join Date
    Aug 2008
    Location
    Las Vegas Nevada USA
    Posts
    6,171

    Default

    Quote Originally Posted by vangogh View Post
    Interesting idea. I suppose it can mess up regular commenting, though not that much and it's probably not a big deal if you prefer the contact form anyway.

    I've been using a plugin called Contact Form 7 lately and it's really nice. Very easy to use. It creates a shortcode you can drop into any post or page and you have a contact form.

    On my site I just coded up the contact form and dropped it into the sidebar. It's easy enough for me to do anyway. The idea of letting them all come through WordPress is interesting though.
    Yeah I use Contact form 7 as well. This is only useful (obviously) if you are using WP as a static site. If you are using it as a blog, then this wouldn't make any sense.
    I just kind of figured since it's already there, and the basic fields are the same.
    I do use a more in depth form on my contact page (Contact 7) that has more fields, but too much to drop on every page.
    Small Business Web Consultant
    1:1 Web Help for Start Ups, Novices, and DIY’ers

    WordPress Website Design » WordPress Support

  4. #4
    Post Impressionist Array vangogh's Avatar
    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    13,539

    Default

    You could set up the comments the way you described for pages and still use the general comment system for posts. You'd need to include a different comments.php file for the pages and you'd have to deal with moderating all comments. Some blogs do that anyway though.

    Actually you could avoid the comment moderation thing by leaving out the parts where the comments display in the code and only show the form and add a thank you message after the form has been submitted. You'd need to pay attention to your comments, but you should be able to search on pages as opposed to posts easily enough.
    l Search Engine Friendly Web Design | Vanseo Design
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Custom WordPress Themes |Get my book about Design Fundamentals

  5. #5
    Member Needs New Keyboard Array jamestl2's Avatar
    Join Date
    Oct 2009
    Location
    Wisconsin
    Posts
    234

    Default

    I'm using something similar for one of my sites, although the one difference I made was I also installed a private comments plugin:
    cleek WordPress Plugin: Semi-Private Comments

    This way comments can be displayed to only the people who make them, and the admin.

  6. #6
    Post Impressionist Array vangogh's Avatar
    Join Date
    Aug 2008
    Location
    Boulder, Colorado
    Posts
    13,539

    Default

    Interesting plugin. You wouldn't want to use it for all commenting, but I can think of some good uses for hiding comments that way. In fact it might work really well for what eborg wants to do with the contact form.
    l Search Engine Friendly Web Design | Vanseo Design
    l Design, Development, Marketing, and SEO Tutorials | Steven Bradley's Notebook
    l Custom WordPress Themes |Get my book about Design Fundamentals

Posting Permissions

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