Issue submitting a form

I have a form that basically has 2 fieldsets in it, and i've used some jQuer so that you fill out the first fieldset, and then click the "Next" button, which then slides in the 2nd fieldset and you fill that info out and click submit. If I just try to click submit without filling in any fields, it does not give me any error messages, but refreshes the page with a query string in the URL. I'm using almost the same code on other pages of the site that only have 1 fieldset and they display errors just fine.

What could be causing the query string to appear in the url and no error messages to be displayed? I'm thinking it has to do with my Validator, but not exactly sure.

<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(''); //put someone's email address here } // let her rip if (!$this->email->send()) { add_error('There was an error notifying'); return FALSE; } return TRUE; } } }


  • edited 11:56AM
    Are there any javascript errors when you click the button? Also, In your form open tag add method="post" and see if that does the trick:
    $vars['formOpen'] = $this->form->open('id="estimate"');
  • edited 11:56AM
    Adding the method="post" worked. Thanks.
Sign In or Register to comment.