Create an enquiry form using Expression Engine

Expression engine is a CMS based on the ever popular PHP Framework  “CodeIgniter”. Basically meaning that anything you can create in codeigniter can be created or developed for Expression Engine. Below is a form built into a template file in Expression Engine 2. Copy the code paste it into a template and try out the form.

<h3>Contact Form</h3>
<div id="contactform">
<?php
	if( ! isset($_POST['formsubmit'])){

?>
<p><i>All fields are compulsory.</i></p>

<form id='contact_form' action='' method='POST' >

<input type='hidden' name='recipient' id='recipient' value='' />
<input type="text" id="uname" name="uname" class="uname" value="Name" />
<input type="text" id="sname" name="sname" class="sname" value="Surname" /><br /><br />
<input type="text" id="email" name="email" class="email" value="Email Address" />
<input type="text" id="tnum" name="tnum" class="tnum" value="Contact Number" /><br /><br />
<input type="text" id="cellnum" name="cellnum" value="Cell Number" />
<select name="department" >
<option value="info@website.co.za">General</option>
<option value="finance@website.co.za">Finance</option>
</select>
<br /><br />
<textarea id="message" name="message" class="message" rows="6" cols="60">Comment</textarea>
<br /><br />
<input name="formreset" id="formreset" type='reset' value="" />
<input name="formsubmit" id="formsubmit" type='submit' value="" />
</form>
<? }else{

$this->EE->load->helper(array('text','url'));
$this->EE->load->library('email');
$message = $this->EE->load->view('contact','',TRUE);

$this->EE->email->wordwrap = true;
$this->EE->email->mailtype = 'html';
$this->EE->email->from($_POST['email'], $_POST['uname']);
$this->EE->email->to($_POST['department']);
$this->EE->email->subject("Contact message from website");
$this->EE->email->message($message);
$this->EE->email->Send();

echo "<p>Thank you for your submission, we will contact you shortly.</p>";

}
?>
</div>

The Department select box allows the user to specify to which email address they want to send the form to. The message view that sends to the recipient is a separate view file in the views folder. As you can see the email being sent is specified as being in html format.

Hope this helps.

Other Posts

%d bloggers like this: