Simple WordPress Forms

I really like the Jetpack plugin. The idea of it is awesome, and most of the modules are great. So far though, I hate the Jetpack forms module. They have perfectly simplified the adding of forms to posts and pages. It is easy to add a form, change the elements and who it goes to, and put it in the post. So why not use it for your forms?

I have found the Jetpack forms impossible to format using CSS without editing the plugin. The stock formatting of the forms is adequate for many sites, but for many custom themes, you’ll need the ability to customize the CSS. What about the formatting of the email that comes back from the form? That isn’t alterable via the Jetpack forms.

You found this page, so I’m guessing you’ve already realized your need for forms. So if Jetpack doesn’t cut it, what are your options? There are many other plugins that build forms, some more functional than others, but I have a simple solution that has worked well for me. Make a simple template that includes the form, then you can style it with CSS to your hearts content, and control what the resultant email looks like.

Your first step is to create a template file for your theme. Use this code, alter it to add the fields that you need, put your email address in the send_to spot, and upload it with your theme files.

if(isset($_POST['submit'])) {    // execute if the form has been submitted
	// --- add in any new variable you add to the form here
	$username = $_POST['username'];
	$email = $_POST['email'];
	$phone = $_POST['phone'];
	$area = $_POST['area_of_interest'];
	$comment = $_POST['comment'];
	$send_to = $_POST['send_to'];

// --- add your variables into the email - \n gives a newline
$formcontent="Your_Website Contact Form Submission - $area\n\nFrom: $username \nEmail: $email \nPhone: $phone \n \n$comment";
$subject = "Your_Website Contact Form";
$mailheader = "From: $email \r\n";

wp_mail($send_to, $subject, $formcontent, $mailheader) or die("Error!");
echo <<< EOR

Thank You, Your Comments Or Questions Have Been Submitted

I'll respond to any questions or comments as soon as I can. Here is your follow up message, maybe include a link to somewhere else.

EOR; } else { echo <<< EOT <form name="contactform" action="" method="POST" id="my_custom_form">
Interest 1 Interest 2 Interest 3

I'll respond to any questions or comments as soon as I can. This is where you would add your message to the bottom of the form.

EOT; } ?>

Leave a Comment

Your email address will not be published. Required fields are marked *