Welcome Guest, Not a member yet? Register   Sign In
Form acting different in IE and Chrome
#1

[eluser]MRosenello[/eluser]
This issue has been bugging me for quite a few days now. In IE I have a form that when submitted the first time does what expected; however if it wont't let me submit the same form again unless I close IE and reopen it. The second time I submit the form this line seems to be evaluating to false: $this->form_validation->run() == FALSE.

However, in chrome the form works fine every time. Anyone ever see this before, or know what may be causing it? Below is the function in the controller that seems to be giving the issues.

Also, I am quite new to CI. Any help is much appreciated.

Code:
function confirmOrder($items)
{
  
  $this->load->helper('form');
  $this->load->library('form_validation');
  $this->form_validation->set_rules('EID','EID','required');
  //echo($this->form_validation->run());
  $data['eid'] = $this->session->userdata('EID');
  $data['contactPhone'] = $this->session->userdata('contactPhone');
  $EID = $data['eid'];
  $data['firstName'] = $this->session->userdata('firstName');
  $data['lastName'] = $this->session->userdata('lastName');
  $data['user'] = $this->session->userdata('lanID');
  $data['domain'] = $this->session->userdata('domain');
  $data['orderItems'] = $this->request_model->finishOrder($items);
  
  $validations = $data['orderItems'];
  for ($i=1;$i<=count($validations);$i++){
   if(isset($validations[$i]['validation'])){
   foreach($validations[$i]['validation'] as $validationID){
    $id = $i."__".$validationID;
    $this->form_validation->set_rules($id,$validationID,'required');
    //echo($validationID);
   }
   }
  
  
  }
   //echo($validations[1]['validation'][1]);
  
  
  $data['items'] = $items;
  $orderConvert = $data['orderItems'];
  $arrValues= array();
  for($i=1;$i<= count($orderConvert);$i++)
  {
   array_push($arrValues,$orderConvert[$i]['name'].", ".$orderConvert[$i]['ID']);
   //$orderDesc[$i] = $orderConvert[$i]['model'].", ".$orderConvert[$i]['part_no'];
  }
  
  $orderArray = $data['orderItems'];
  if ($this->form_validation->run() == FALSE)
  {
   //echo("WHY IS IT FALSE");
   //echo($this->form_validation->run());
   $this->load->view('requestFinalize.php',$data);
  }
  else
  {
   //$arr2 = $this->input->post();
   //print_r($arr2);
   //print_r($this->input->post());
   $formInputs = $this->input->post();
   $count = $formInputs['itemCount'];
   $values = array();
   for($i=1;$i<=$count;$i++){
    foreach($formInputs as $key => $value){
    if (substr($key,0,1)==$i && substr($key,3) != "assignmentGroup")
    {
     $key = str_replace($i."__","",$key);
     $key = str_replace("_"," ",$key);
     array_push($values,"".$key." :".$value."\n");
    }
   $data['user'] = $this->session->userdata('lanID');
   $data['domain'] = $this->session->userdata('domain');
   $data['values'] = $formInputs;
   //$data['IMnumber'] = $this->request_model->create_request($arrValues,$EID);
   //$data['IMnumber'] = $this->request_model->create_dynamic_request($formInputs);
  
   }
   }
   $formInputs['items'] = $items;
   $this->session->set_userdata('currentCart', $formInputs);
   $data['test'] = $this->session->userdata('currentCart');
   //$this->session->unset_userdata('currentCart');
   $this->load->view('requestConfirm.php',$data);
  }
  
}
#2

[eluser]MRosenello[/eluser]
Does anyone know how the form validation works? (ie. where $this->form_validation->run() is set, or how it is set, or what that function is returning?)

Is this set in some sort of a CI session? This is the only thing I can think that would cause this issue I am having since CI sessions are stored as cookies right?

Thanks again for any insight you may have.
#3

[eluser]InsiteFX[/eluser]
Code:
if ($this->form_validation->run() == FALSE)
{
    // Form not Validated.
    $this->load->view('myform');
}
else
{
    // For Validated.
    $this->load->view('formsuccess');
}
#4

[eluser]MRosenello[/eluser]
Yes I get that part. But I mean how is that function ($this->form_validation->run()) returning a value. What does it check/set for this? I am trying to figure out why it is not acting consistent across browsers (at least it seems that way right now).

I am asking this because it is server side script, and browser should not matter unless it is setting some sort of cookie to verify whether or not the validation ran or not.

-Mike

#5

[eluser]InsiteFX[/eluser]
I use it with IE9 FireFox 13 and Chrome and have no problems so I do not think that you are having aa bowser problem.

Why are you read session data to grab the form fields you should be using $this->input->post()
#6

[eluser]CroNiX[/eluser]
Did you happen to look at the Form Validation library in the user guide?
#7

[eluser]MRosenello[/eluser]
I am using the form validation class. Using IE when I submit the form it runs the validations (and outputs the validation errors if there are any) Also, it continues to run the validation every time it fails the validation. It also submits the form correctly the first time I try when all validation passes; however, if I go back to the same form at any point while keeping IE open, it won't submit the form and no validation errors are thrown.

The reason I am storing the post values in a session is because the user is presented with a confirmation page next where all of the values they entered are presented to them to confirm. Then once they hit a confirm button it grabs all of these values and makes a web services call to create a record in another application and then unsets the session variables.

Also, it works perfectly fine in Chrome and firefox just not IE7-9 (didnt test IE6). I inherited the code the way it is, so I guess I will try rebuilding the piece that stores the values in a session and see what happens.

All of the input and validations on the form are dynamic. The names and requirements are created in another DB that I am just reading from. Below is the code I am using to set the form validations. Maybe there is something wrong with the way I am doing that?

Again, this is all working fine in chrome and on the first submit of the form in all versions of IE(7-9).

Code:
$data['orderItems'] = $this->request_model->finishOrder($items);
  
  $validations = $data['orderItems'];
  for ($i=1;$i<=count($validations);$i++){
   if(isset($validations[$i]['validation'])){
   foreach($validations[$i]['validation'] as $validationID){
    $id = $i."__".$validationID;
    $this->form_validation->set_rules($id,$validationID,'required');
    //echo($validationID);
   }
   }
#8

[eluser]CroNiX[/eluser]
I think your issue is tied to sessions. IE has problems. Check to make sure there isn't an underscore in your session cookie name. There is one by default.

Another thing I'd suggest is to not even load your form validation, set the rules or run it unless the form has actually been posted.
Code:
//Check that the form was submitted
if ($this->input->post())
{
  $this->load->library('form_validation');

  //set rules...
  $this->form_validation->set_rules('EID','EID','required');
  //etc...

  if ($this->form_validation->run() === FALSE)
  {
    //do stuff for form failure.
    //Generally I don't do anything here as the form will load below and
    //if there are errors it will display them
  }
  else
  {
    //do stuff for successful form submission
    //save data, maybe set success message that the view will display (flashdata)
  }
}

//do stuff regardless of whether form was submitted (show form)
#9

[eluser]MRosenello[/eluser]
Thanks for the help guys... I really appreciate it. I am going to give that a try and will let you know how it works.

-Mike
#10

[eluser]MRosenello[/eluser]
I tried both of these with no luck. I also noticed that the post values arent always being passed in IE. If the form is blank or has validation errors, the post values are sent and the validation errors are showing up in the view; however, when all of the required fields are filled in there seems to be no post values being sent (still working fine on the first time I submit the form).

I will keep debugging today and hopefully I find something.

-Mike




Theme © iAndrew 2016 - Forum software by © MyBB