Many sites have the need for a small contact form. Gathering user information is the general purpose, and information is usally emailed to a department or person.
This attached code allows Drupal site administrators to create a node that will perform the task of a contact form. Easy to learn HTML skills are required to alter the form into a specific purpose. The example code is setup with 4 fields, including Name and Email which should always be used. The rest of the fields allow for customizing the form for a specific purpose.
Instructions
- Create a new "Page" node.
- Select the "PHP" input format, and click preview. This will tell Drupal that you want to use PHP and to not touch the source code.
- Paste the code found below into the body of the page.
- Alter the code to suit your needs:
- Change the destination email address.
- Set a custom subject.
- Add or Remove fields to the form and email.
- Modify the required fields.
- Test your form. Each required field should be required, and the form should reject a submission if sent less than ten seconds after the form was loaded.
Add and Remove Fields
To add a field to the form you will need to:
- Copy and modify the table row that holds the field.
Be sure to change the "name" property of the input element and the "for" property of the label element. - Insert a check into the required fields tests to check the new input element.
- Add the new field to the email template.
This is under the MESSAGE declaration and can be added by following the format of the other fields already in the message.
To remove a field simply follow the above steps in reverse. Be sure you don't remove the Name or Email fields as they are required for sending the email.
For help with the required HTML and PHP see:
*Note: This functionality may be replaced in the future with the WebForm module.

