0

I need to create a very simple contact form in the homepage with just 3 fields.Is there a way for showing the contact form without a plugin?

I dont want to create a page with a contact form template for that.

thk.

3
  • 1
    So what exactly is your question? How to write a contact form? (that's not really something anyone can wrap up in a simple answer, because quite frankly creating a contact form *properly* requires more than a few lines of simple code). Google and examining the existing contact form plugins would be good places to start for ideas on how to write a contact form.
    – t31os
    Commented Jul 28, 2011 at 12:12
  • well, i've done contact forms before for php websites and contact templates for wordpress but never done a "homepage" form.I think that the easy way is use a widget.I need the form in the footer and it's widget ready so i'll go with contact form 7 plugin. I thought there would be some wp functionallity for sending form content by email.
    – Oterox
    Commented Jul 28, 2011 at 13:12
  • There's no create_a_contact_form() function in WordPress if that's what you're hoping for ... though WordPress does have many helper functions for different tasks, if you want to ask specifics i'll try to answer.. (example: is there a function that does X?).
    – t31os
    Commented Jul 28, 2011 at 13:16

1 Answer 1

2

The Agregado Theme comes with a little contact form I modified for one of my themes, I guess it's ok for you to use it as long as the credits remain there.

<?php
    //Contact script created by Tim McDaniels and Darren Hoyt for the Mimbo Pro and Agregado themes, modified by Mario Aguiar cuz it didn't work.
    //May be re-used with credits intact
    if($_REQUEST['submit']): 
        $admin_email = get_option( "admin_email" );
        $admin_subject = 'Inquiry';
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: ' . $admin_email . "\r\n";
        $body = "<blockquote>
            Name: " . $_REQUEST['Name'] . "<br/>
            Email: " . $_REQUEST['Email'] . "<br/>
            Message:<br/>" . $_REQUEST['Message'] . "<br/>
            <hr/>
            Remote Address: " . $_SERVER['REMOTE_ADDR'] . "<br/>
            Browser: " . $_SERVER['HTTP_USER_AGENT'] . "
            <hr/>
        </blockquote>";
        mail ($admin_email, $admin_subject, $body, $headers);
    endif; ?>
<form onsubmit="return(submitContactForm(this));" id="contactform" action="">
    <h5>Contact</h5>
    <fieldset>
        <legend>Contact</legend>
        <label for="user-name">Name:</label>
        <input type="text" id="user-name" name="Name" class="field" title="Enter name here" />
        <label for="user-email">Email:</label><br />
        <input type="text" id="user-email" name="Email" class="field" title="Enter email address here" />
        <label for="user-comment">Message:</label>
        <textarea id="user-comment" name="Message" class="field" cols="" rows="4" title="Enter comments here"></textarea>
        <input type="hidden" name="submit" value="1" />
        <input type="submit" value="" id="homeContactSubmit" class="button" />
    </fieldset>
</form>

You'll have to add some captcha to prevent spam, but it works. I have this working on my theme Celeste.

1
  • The theme is GPL so it should be ok(i think), any code posted on a SO/SE site must be compatible with the CC licensing, else it ideally shouldn't be posted, please see this SO thread, i'm pretty sure SE sites follow the same standard/rules as the SO sites, so should apply here to(i believe).
    – t31os
    Commented Jul 28, 2011 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.