Can I add fields? How do I add a form field?

The mail form was designed to be adapted and added to without PHP knowledge, however it does help to know a little bit of HTML.

To add fields, open the mail form file and scroll down to the actual HTML form (it starts <form action ...). Add the field somewhere between the opening <form> and closing </form>; I suggest using the existing fields as a starting point.

Code Sample – text field

To add a text field, e.g. Company, below the existing Website URL field

Find:

	<label for="url">Website URL:</label> 
		<input type="text" name="url" id="url" value="<?php get_data("url"); ?>" /><br />

Below, add:

	<label for="company">Company:</label> 
		<input type="text" name="company" id="company" value="<?php get_data("company"); ?>" /><br />

Save the file & re-upload.

Code Sample – checkbox field

To add a checkbox field, e.g. an opt-in to a newsletter, before the submit button:

Find:

</p>
<p>
	<input type="submit" name="submit" id="submit" value="Send" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> />
</p>

Above, add:

	<label for="optin">Would you like to receive our newsletter?</label>
		<input type="checkbox" name="optin" value="yes" /> Yes

Or to add multiple checkbox fields (a selection of choices for the user), find the submit button code as above and add above it:

	<label>Foods I like include:</label>
		<input type="checkbox" name="foods[]" value="cheese" /> Cheese
		<input type="checkbox" name="foods[]" value="bread" /> Bread
		<input type="checkbox" name="foods[]" value="bacon" /> Bacon

Make sure you edit each checkbox value="" as well as the text displayed.

Save the file & re-upload.

Get Premium

All the great features of the free contact form, and more besides...

Buy Now - £19

  • UTF-8 support: ideal if you receive mails containing characters such as é, ó, ü and so on
  • Even more spam protection: take advantage of better functionality in newer versions of PHP
  • Repeat submission protection: stop people from submitting the form multiple times in a row
  • Read more about the premium mail form...