Quick Tutorial Needed - Contact Form

edited December 2010 in Feature Requests
If possible, I'd like someone to post a quick tutorial (including where to place files) on how to create a simple "Contact" form that sends an e-mail with the contents of the form.
Specifically, I was curious if it was possible to still allow editing of the form-page contents from within the editor while still retaining the functionality of the form.
Any pointers/tips will be greatly appreciated!


  • edited 1:47AM
    The 0.91 branch has an example website that uses a contact controller you can use as an example.

    However, the page is being pulled from the contact view file instead of the CMS. To have it pulled from the CMS, open up the contact controller and change line 40 to:
    $page_init = array('location' => 'contact', 'render_mode' => 'cms');

    Hope that helps.
  • edited December 2010
    This was just what I was looking for, however I'm running into an error when trying to load the Contact page:

    Fatal error: Class 'CI_Controller' not found in /home/fuel/application/controllers/Contact.php on line 2

    Thanks in advance for the assistance! FUEL rocks!

    Any suggestions?
  • edited December 2010
    Fixed it!

    Changed line 2 to the following:
    class Contact extends Controller {

    (changed CI_Controller to Controller)

    And now the form displays, but it doesn't seem to be accepting the post data correctly (perhaps session->flashdata isn't working correctly). Fill in the form and hit submit, yet it just takes me back to the form itself, no message, mail sent, etc.

    Also - Here's what I have in my View (Input at Fuel Admin -> Pages):
    <h1>Contact Us</h1> {if ($session->flashdata('success')) } <p class="success">Thank you for contacting us. We will get back to you shortly.</p> {else } <p>Please fill out the form below to send us any questions:</p> {$form} {/if}
  • edited 1:47AM
    Aha! I answered my own question again... I logged out of the Admin and now it works. Must have been something interfering with the submission of the form when I was logged in as admin.

    This is awesome! Thank you thank you!
  • edited 1:47AM
    No worries. As an FYI, the CI_Controller is CI 2.0 change and that's why you were seeing that error. I'd be curious to know more about what the problem was that you were having. The example provided in the 0.91 version does require you to set the configuration value of "dev_email" in the MY_config.php and may have contributed to the problem you were seeing but am not certain.
  • edited 1:47AM
    Yes, I did set the config value of "dev_email" in MY_config.php, so I don't think it has to do with that.
    Thanks for the heads-up on the CI_Controller vs Controller in CI 2.0. Guess I'd better read something about the changes seeing as it's here already!

    In any case, it's working like a charm now. One item that you may want to add to the User_Docs for the Form Builder Class @ http://www.getfuelcms.com/user_guide/libraries/form_builder (I had to look it up in the CI libraries documentation).

    A quick example of how to configure the library such as:
    $form_params = array('id'=>'contact_form','submit_value' => 'Send Message', 'textarea_rows' => '5', 'textarea_cols' => '28');

    In any case, thanks for the great work. I'm just working on getting my first project completed with FUEL... it's great, and much better suited to what I need to accomplish than a more-bloated CMS like EE.
  • edited December 2010
    I've added that for the Form_builder class and the other libraries in the documentation.
  • edited February 2011

    I'm trying to implement contact form on my clint website, I took all code form your demo website. But it doesn't work, on submission it just reload the contact page.
    I'm running the latest build of FUEL CMS, and here is what i have in contact controller:

    class Contact extends CI_Controller {

    function __construct()

    function index()

    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);

    $fields = array();
    $fields['first_name'] = array('label' => 'Имя','required' => TRUE);
    $fields['last_name'] = array('label' => 'Фамилия','required' => TRUE);
    $fields['email'] = array('required' => TRUE);
    $fields['question'] = array('label' => 'Ваш Вопрос','required' => TRUE, 'type' => 'textarea');


    // will set the values of the fields if there is an error... must be after set_fields
    $this->form_builder->display_errors = TRUE;
    $vars['form'] = $this->form_builder->render();

    // use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
    $page_init = array('location' => 'contact', 'render_mode' => 'cms');
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);

    function _process($data)
    Set rules up here so we can pass them to the form_builder to display errors.
    validator_helper contains the valid_email function... validator helper automatically gets' looded with Validation Class'

    $this->validator->add_rule('first_name', 'required', 'Please enter in an first name', $this->input->post('first_name'));
    $this->validator->add_rule('last_name', 'required', 'Please enter in an last name', $this->input->post('last_name'));
    $this->validator->add_rule('email', 'valid_email', 'Please enter in a valid email', $this->input->post('email'));
    $this->validator->add_rule('question', 'required', 'Please enter in an question', $this->input->post('question'));

    if ($this->validator->validate())

    // send email
    $this->email->from($data['email'], $data['first_name'] . ' ' . $data['last_name']);

    YOU MUST FILL OUT THE CORRECT dev_email config in application/config/MY_config.php
    AND/OR THE CORRECT TO email address
    // check config if we are in dev mode
    if ($this->config->item('dev_mode'))
    // need to fill this out to work
    $this->email->subject('Website Contact Form');
    $msg = "The following information was submitted:\n";
    foreach($data as $key => $val)
    $msg .= humanize($key, 3).": ".$val."\n";

    // let her rip
    if (!$this->email->send())
    add_error('There was an error notifying');
    return FALSE;

    return TRUE;


    and my view:

    <?php fuel_set_var('layout','with_sidebar') ?>


    <?php if ($this->session->flashdata('success')) : ?>

    Спасибо! Мы скоро с вами свяжемся!

    <?php else : ?>

    Пожалуйста, заполните контактную форму:

    <?php echo $form; ?>
    <?php endif; ?>

    please let me know what I'm doing wrong?

    I'd really appreciate your help!
  • edited 1:47AM
    Try removing $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR']
  • edited 1:47AM
    thanks that worked
  • edited 1:47AM
    Hello !

    I have the contact form working properly, but in the dashboard I have a new menu called "Modules" with "Contact" under it, and when I click on it, it say "An Error Was Encountered
    Unable to locate the file: contact_model.php"
    Do you know what this mean ?

    Thanks you very much,
  • edited 1:47AM
    That sounds like you create a simple module using the fuel/applicaiton/config/MY_fuel_modules.php? If so, there needs to be a contact_model for the module to map to. By default it assumes that the model is the name of the module with the "_model" as a suffix.
  • edited 1:47AM
    githubs link show not found..
  • edited 1:47AM
    That branch has probably been deleted by now, as FUEL CMS is now in version 1.0.5 .

    However, I have been developing an advanced module with Contact Form functionality.
Sign In or Register to comment.