• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble Submitting Form

I have an existing application I am trying to debug. CodeIgniter version is 1.7.2.

On submission, the form returns itself with the fields cleared. I have troubleshot the issue down to the $_POST array being cleared of data when the form validation is run.
I have verified that the $_POST array exists at the top level index.php and in the Router.php. I verified the $_POST exists right before the call_user_func_array() function call in CodeIgniter.php and is empty after that call. It is also empty once inside the controller.

Any ideas where to look for the issue? I'm new to CodeIgniter but not new to PHP.


Well CodeIgniter works with its own input class, not directly with $_POST. Are you sure that after submitting your form, it's not just showing the form again? Is there code in place to make sure that the POST variables are repopulated into the form?

Show us some code or something. Also, you should upgrade your install whenever possible, since we're up to 2.1.x

Here's the view:
<form action='/add-new-property/save_listing_address' method='POST'>

  <div class='TDFormHeader'>Enter Property Address</div>
  <table width='100%' cellPadding='3' cellSpacing='2' class='TDForm'>
    <td valign='top' width='150'><span class='FormTitle'>Address:</span></td>
    <td>&lt;input type='text' name='address' value="&lt;?php echo set_value('address');?&gt;"&gt;&lt;div class='ErrorDiv'>&lt;?php echo form_error('address'); ?&gt;</div></td>
    <td valign='top' width='150'><span class='FormTitle'>Space Number:</span></td>
    <td>&lt;input type='text' name='space' value="&lt;?=set_value('space');?&gt;"&gt;&lt;div class='ErrorDiv'>&lt;?php echo form_error('space'); ?&gt;</div></td>
    <td valign='top' width='150'><span class='FormTitle'>City:</span></td>
    <td>&lt;input type='text' name='city' value="&lt;?=set_value('city');?&gt;"&gt;&lt;div class='ErrorDiv'>&lt;?php echo form_error('city'); ?&gt;</div></td>
    <td valign='top' width='150'><span class='FormTitle'>State:</span></td>
    <td>&lt;?=$this->system_vars->state_array_select_box(set_value('state'));?&gt;<div class='ErrorDiv'><div class='ErrorDiv'>&lt;?php echo form_error('state'); ?&gt;</div></td>
    <td valign='top' width='150'>&nbsp;</td>
    <td>&lt;input type='submit' name='sub' value="Continue"&gt;&lt;/td>


part of the controller action:
function save_listing_address(){

  $this->form_validation->set_rules('address', 'Address', 'trim|required|xss_clean');
  $this->form_validation->set_rules('space', 'Space', 'trim|xss_clean');
  $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
  $this->form_validation->set_rules('state', 'State', 'trim|required|xss_clean|exact_length[2]');
  if ($this->form_validation->run()){  
   $AddressPlotter = $this->system_vars->address_plotter(set_value('address'),set_value('city'),set_value('state'));
     $GenerateError = "<b>ADDRESS ERROR !!!</b><br>The address you have entered seems to be invalid.";
     if(isset($AddressPlotter['Address']) && isset($AddressPlotter['City']) && isset($AddressPlotter['State'])) $GenerateError .= "<br><u>The closes match is:</u> ".$AddressPlotter['Address'].", ".$AddressPlotter['City'].", ".$AddressPlotter['State']." ".$AddressPlotter['Zip'];
     $NPArray['address'] = $AddressPlotter['Address'];
     $NPArray['space'] = set_value('space');
     $NPArray['city'] = $AddressPlotter['City'];
     $NPArray['state'] = $AddressPlotter['State'];
     $NPArray['zip'] = $AddressPlotter['Zip'];
     $NPArray['lon'] = $AddressPlotter['Longitude'];
     $NPArray['lat'] = $AddressPlotter['Latitude'];
     $this->session->set_userdata('np_address', $NPArray);
    $this->form_validation->set_message('check_address', "<b>ADDRESS ERROR !!!</b><br>The address you have entered does NOT exist.<br>");
    return false;

Here's the code snippet in the Form_Validation showing why I was interested in the $_POST array
  * Run the Validator
  * This function does all the work.
  * @access public
  * @return bool
function run($group = '')
  // Do we even have any data to process?  Mm?
  if (count($_POST) == 0)
   return FALSE;

The validater is always returning false and when I examine the $_POST array here, it is empty. The form redisplays itself because it thinks nothing has been submitted.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.