« See all FAQs for Blue Earth Wordpress theme

Can I add a field to the contact form?

It is not possible yet to add a field to the contact form through the admin panel, but it can easily be done with a little coding. Here is a quick guide on how to add you own contact field:

1. Open the file footer.php, and scroll down to the contact form : you can add your field here anywhere within the block . You can copy the markup of the field name, and just change the attributes to match you field name. Just don’t touch the field city, it’s a trap for spam bots.

For instance:

<p class=”required”>
<label for=”my_field”><?php _e(‘My Field’, ‘blue-earth’); ?></label><br />
<input type=”text” name=”my_field” id=”my_field” value=”” class=”input-large” tabindex=”2” />
</p>

You can remove the class required if you don’t want your field to be styled as mandatory.

2. Open the file contact.php, and add these lines:

After line 12:
$my_field = trim($_POST['my_field']);

If your field is mandatory, add it to line 27:
elseif ($name == '' or $mail == '' or $message == '' or $my_field == '')

At line 43, add your field to the replacement string array:
$replace = array( '[name]' => $name, '[mail]' => $mail, '[message]' => $message, '[my_field]' => $my_field, '[blog_name]' => get_bloginfo('name') );

3. Save and upload your files.

You can now use the tag [my_field] (or whatever you named it) in the contact panel of the template admin.

by
by
by
by
by
by