cms page w/contact form->controller->cmspage w/contact form

edited September 2012 in Modules
I'm using the 1.0 beta
i have a contact form in the body of a cms created frontend page (/contact_form) which posts to email controller. I only did it this way as a means to simplify because i couldn't get my "every page sidebar contact form" to work with controller either. This works, but as you can see, the controller points back to view files instead of the cms created front end contact_form page so it renders views that have not been styled and are not in database that i had created just for testing the email and validation. I would like the controller to post back to the frontend cms page. Ideally, i'd like to stick my sidebar contact form back in the sidebar and it be able to communicate with controller no matter what page it's on and render success view or refresh right in the sidebar, but getting the controller to point back to the cms page would be fine too.

div from /contact_form cms page:

<div class="contactform"> {$load->helper('form')} {form_open('email/send')} {$name_data = array( 'name' => 'name', 'id' => 'name', 'value' => set_value('name'), 'class' => 'contact' )} <p>{form_error('name')}<label for="name">Name: </label>{form_input($name_data)}</p> <p>{form_error('email')} <label for="name">Email Address: </label> <input type="text" class="contact" name="email" id="email" value="{set_value('email')}"> </p> <p>{form_error('email_again')} <label for="name">Email Again, Please:</label> <input type="text" class="contact" name="email_again" id="email_again" value="{set_value('email_again')}"> </p> <p> <label for="name">Subject:</label> <input type="text" class="contact" name="subject" id="subject" value="{set_value('subject')}"> </p> <p>{form_error('message')} <label for="name">Message:</label> <input type="textarea" rows="5" class="contact" name="message" id="message" value="{set_value('message')}"> </p> <p>{form_submit('submit', 'Submit')}</p> {form_close()} </div><!--end Contact-block-->

email controller:

<?php /** * Sends email */ class Email extends CI_Controller { function __construct() { parent::__construct(); } function index() { $this->load->view('contact_form'); } function send() { $this->load->library('form_validation'); // field name, error message, validation rules $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|matches[email_again]'); $this->form_validation->set_rules('email_again', 'Email Again, Please', 'trim|required'); $this->form_validation->set_rules('subject', 'Subject', ''); $this->form_validation->set_rules('message', 'Message', 'trim|required'); if($this->form_validation->run() == FALSE) { $this->load->view('contact_form'); } else { // validation has passed. Now send the email $name = $this->input->post('name'); $email = $this->input->post('email'); $subject = $this->input->post('subject'); $message = $this->input->post('message'); $this->load->library('email'); $this->email->set_newline("\r\n"); $this->email->to('info@somesite.com'); $this->email->from('admin@somesite.com', 'Admin'); $this->email->reply_to($email); $this->email->subject($subject); $this->email->message($message); $path = $this->config->item('server_root'); if($this->email->send()) { $this->load->view('message_sent'); } else { show_error($this->email->print_debugger()); } } } }

Comments

  • edited 1:53AM
    In your controller, you could set a flash message and redirect instead of loading a view?

    $this->session->set_flashdata('error', 'No good'); redirect(current_url());

    You could have your contact form as a block or straight in the layout too. Another way again.. could ajax the contact form submit and just pipe a json response back.

    The code tags are: without hyphens.
  • edited 1:53AM
    thanks for the response. i take a look at it again.
Sign In or Register to comment.