It looks like you're new here. If you want to get involved, click one of these buttons!
<div id="slidingForm">
<?php if ($this->session->flashdata('success')) : ?>
<p class="success">Thank you for contacting us. We will get back to you shortly.</p>
<?php endif; ?>
<?php echo $formOpen; ?>
<fieldset id="firstFieldset">
<legend>Contact Info</legend>
<?php echo $form1; ?>
</fieldset>
<fieldset id="secondFieldset">
<legend>Location Info</legend>
<?php echo $form2; ?>
</fieldset>
<?php echo $formClose; ?>
</div>
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Request_for_estimate extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('session');
$this->load->library('form_builder', array('css_class' => 'left',
'section_tag' => 'h3',
'display_errors' => TRUE,
'render_format' => 'divs',
'boolean_mode' => 'enum',
'show_required' => FALSE,
'use_form_tag' => FALSE));
$this->load->library('form');
// if the page has been posted (aka if the form on the page has been submitted)
if (!empty($_POST) AND $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR'])
{
// put your processing code here... we show what we do for emailing. You will need to add a correct email address
if ($this->_process($_POST))
{
$this->session->set_flashdata('success', TRUE);
redirect('request_for_estimate');
}
}
// build the form
$fields = array();
$fields['name'] = array('label' => 'Contact Name', 'required' => TRUE, 'class' => 'input left first');
$fields['company'] = array('label' => 'Company', 'required' => TRUE, 'class' => 'input left');
$fields['address'] = array('label' => 'Address', 'required' => TRUE, 'class' => 'input left');
$fields['phone'] = array('label' => 'Phone', 'required' => FALSE, 'class' => 'input left');
$fields['fax'] = array('label' => 'FAX', 'required' => FALSE, 'class' => 'input left');
$fields['email'] = array('label' => 'Email', 'required' => TRUE, 'class' => 'input left');
// add the next button
$params = array('value' => 'Next', 'use_input' => FALSE, 'name' => 'next');
$this->form_builder->other_actions = $this->form_builder->create_button($params);
$this->form_builder->submit_value = '';
$fields2['inspection'] = array('label' => 'Inspection and Estimate Required by When?', 'required' => TRUE, 'class' => 'input left');
$fields2['location'] = array('label' => 'Name of Location', 'required' => TRUE, 'class' => 'input left');
$fields2['address'] = array('label' => 'Address', 'required' => TRUE, 'class' => 'input left');
//$fields2['contactName'] = array('label' => 'Contact Name', 'required' => TRUE, 'class' => 'input left');
//$fields2['phoneNum'] = array('label' => 'Phone Number', 'required' => FALSE, 'class' => 'input left');
//$fields2['access'] = array('label' => 'Access', 'required' => TRUE, 'class' => 'input left');
$fields2['reason'] = array('label' => 'Reason for Estimate', 'required' => TRUE, 'class' => 'input left');
$fields2['comments'] = array('label' => 'Comments', 'required' => TRUE, 'class' => 'input left');
$this->form_builder->set_fields($fields);
$vars['form1'] = $this->form_builder->render();
$this->form_builder->submit_value = 'Send';
// add the back button
$params = array('value' => 'Back', 'use_input' => FALSE, 'name' => 'back');
$this->form_builder->other_actions = $this->form_builder->create_button($params);
$this->form_builder->set_fields($fields2);
$vars['form2'] = $this->form_builder->render();
// will set the values of the fields if there is an error... must be after set_fields
$this->form_builder->set_validator($this->validator);
$this->form_builder->set_field_values($_POST);
$vars['formOpen'] = $this->form->open('id="estimate"');
$vars['formClose'] = $this->form->close();
// use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
$page_init = array('location' => 'request_for_estimate', 'render_mode' => 'cms');
$this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
$this->fuel_page->add_variables($vars);
$this->fuel_page->render();
}
function _process($data)
{
$this->load->library('validator');
$phone = $this->input->post('phone');
$fax = $this->input->post('fax');
// rules for the form elements
$this->validator->add_rule('name', 'required', 'Please tell us your name!', $this->input->post('name'));
$this->validator->add_rule('address', 'required', 'Please tell us the address with the leak!', $this->input->post('address'));
if(!is_null($phone) && !empty($phone))
{
$this->validator->add_rule('phone', 'valid_phone', 'This phone format doesn\'t look right. Try this one: xxx-xxx-xxxx.', $this->input->post('phone'));
}
if(!is_null($fax) && !empty($fax))
{
$this->validator->add_rule('fax', 'valid_phone', 'This fax format doesn\'t look right. Try this one: xxx-xxx-xxxx.', $this->input->post('fax'));
}
$this->validator->add_rule('email', 'required', 'Please tell us your email address!', $this->input->post('email'));
$this->validator->add_rule('email', 'valid_email', 'This email seems incorrect, please try again!', $this->input->post('email'));
$this->validator->add_rule('inspection', 'required', 'When do you need the inspection by?', $this->input->post('inspection'));
$this->validator->add_rule('location', 'required', 'Please tell us the name of the building or location.', $this->input->post('location'));
$this->validator->add_rule('address', 'required', 'Please tell us the address of the building!', $this->input->post('address'));
$this->validator->add_rule('reason', 'required', 'Please tell us why you\'re inquiring!', $this->input->post('reason'));
if ($this->validator->validate())
{
$this->load->library('email');
$this->email->from($data['email'], $data['name']);
$this->email->subject('Prime WaterProofing and Roofing Website Leak Form');
$msg = "The following information was submitted: \n";
$msg .= "Name\t".$this->input->post('name')."\n";
$msg .= "Address\t".$this->input->post('address')."\n";
$msg .= "Email\t".$this->input->post('email')."\n";
// only email the phone number and fax number if they exist
if(!empty($phone) && !is_null($phone))
{
$msg .= "Phone\t".$this->input->post('phone')."\n";
}
if(!empty($fax) && !is_null($fax))
{
$msg .= "Fax\t".$this->input->post('fax')."\n";
}
$msg .= "Inspection\t".$this->input->post('inspection')."\n";
$msg .= "Location\t".$this->input->post('location')."\n";
$msg .= "Address\t".$this->input->post('address')."\n";
$msg .= "Reason\t".$this->input->post('reason')."\n";
$msg .= "Comments\t".$this->input->post('comments')."\n";
//check config if we are in dev mode
if($this->config->item('dev_mode'))
{
$this->email->to($this->config->item('dev_email'));
}
else
{
$this->email->to('tomcaflisch@gmail.com'); //put someone's email address here
}
// let her rip
if (!$this->email->send())
{
add_error('There was an error notifying');
return FALSE;
}
return TRUE;
}
}
}
Comments
$vars['formOpen'] = $this->form->open('id="estimate"');