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

#1
[eluser]mcrobertstd[/eluser]
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.

Thanks,
mcrobertstd

#2
[eluser]Aken[/eluser]
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

#3
[eluser]mcrobertstd[/eluser]
Here's the view:
Code:
<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'>
  
   <tr>
    <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>
   </tr>
  
   <tr>
    <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>
   </tr>
  
   <tr>
    <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>
   </tr>
  
   <tr>
    <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>
   </tr>
  
   <tr>
    <td valign='top' width='150'>&nbsp;</td>
    <td>&lt;input type='submit' name='sub' value="Continue"&gt;&lt;/td>
   </tr>  
  </table>

&lt;/form&gt;

part of the controller action:
Code:
function save_listing_address(){
                                      $this->load->library('form_validation');

  $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'));
   if(isset($AddressPlotter)){
  
    if(isset($AddressPlotter['warning'])){
    
     $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'];
    
     $this->session->set_flashdata('response',$GenerateError);
     redirect('/add_new_property');
    
    }else{
    
     $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);
     redirect('/add_new_property/community_select');
    
    }
  
   }else{
  
    $this->form_validation->set_message('check_address', "<b>ADDRESS ERROR !!!</b><br>The address you have entered does NOT exist.<br>");
    return false;
  
   }
  
  }else{
  
   $this->load->view('elements/header_view');
   $this->load->view('add_new_property/listing_address');
   $this->load->view('elements/footer_view');
  
  }

}
Here's the code snippet in the Form_Validation showing why I was interested in the $_POST array
Code:
/**
  * 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.

Thanks,
mcrobertstd


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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