Welcome Guest, Not a member yet? Register   Sign In
Form Submit Problem
#1

[eluser]mcrobertstd[/eluser]
On form submission, the form returns itself with input fields cleared.
This is the view "listing_address".
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;
The controller action is
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');
  
  }

}
The form reloads because the form_validator is seeing no post data and returning false. I tried echoing the post data at the top-level index.php and find the post is blank there, as well.
The CodeIgniter version is 1.7.2. Removing the form_validation allows the script to continue to the next page.
The expected result is that with form validation, the website moves on to the next screen and not resubmit the same page with no data.


Messages In This Thread
Form Submit Problem - by El Forum - 05-02-2012, 11:33 AM
Form Submit Problem - by El Forum - 05-02-2012, 11:48 AM
Form Submit Problem - by El Forum - 05-02-2012, 02:23 PM
Form Submit Problem - by El Forum - 05-02-2012, 03:42 PM
Form Submit Problem - by El Forum - 05-03-2012, 04:09 AM
Form Submit Problem - by El Forum - 05-03-2012, 09:59 AM
Form Submit Problem - by El Forum - 05-03-2012, 12:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB