CodeIgniter Forums
Avoiding POSTDATA popup while still using default Validation class... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Avoiding POSTDATA popup while still using default Validation class... (/thread-9117.html)



Avoiding POSTDATA popup while still using default Validation class... - El Forum - 06-12-2008

[eluser]evolve08[/eluser]
Not sure if I'm just doing something wrong or if I'm searching for the wrong thing, but all of the topics I've found don't really seem to solve the problem I'm having.

I'm attempting to use one method for form validation and submission:
Code:
function add()
{
    $data['title'] = "Enter a new component";
          
    $rules['name'] = "trim|htmlentities|required";
    //snip
    $this->validation->set_rules($rules);
            
    $fields['name'] = "name";
    //snip
    $this->validation->set_fields($fields);
          
    if($this->validation->run())
    {
        //post to db
        $this->session->set_flashdata('flash', 'Item has been added');
        redirect('components');
    }
    else
    {
        $this->load->view('header', $data);
        $this->load->view('components/add');
    }
}
It works well, however if I refresh the page after the form fails to validate, if I refresh that page I get a POSTDATA pop-up, which makes complete sense. I'm just wondering what the easiest method is to stop this from happening without writing a decent amount of code for each form.

Basically if I want to avoid the error right now I have to redirect and store the form data in a session. However if I were to do that, then I don't see myself being able to use the form validation class...


Avoiding POSTDATA popup while still using default Validation class... - El Forum - 06-12-2008

[eluser]Nikhil Vijayan[/eluser]
The pop up isn't a bug and as u said makes complete sense

Its the basic working of web and there is no reason we should override it ..

if u hate it that much read the rest

To solve your problem u will surely need to use session

using php inbuilt session can help reduce codes like

Code:
function add(){

// form validation code

if($this->validation->run()){
  //submit to db
  
  redirect('to_page');
  
}
else{
  $_SESSION['form_name_data'] = $_POST;
  redirect('to_form_page');


}

}


and in form page controller


Code:
$data = $SESSION[form_name_data];

  $this->load->view('form_page', $data);


in form view page


Code:
<input name="first_name" value="<?= $first_name ?>">

etc etc.....



Avoiding POSTDATA popup while still using default Validation class... - El Forum - 06-23-2008

[eluser]meigwilym[/eluser]
Try Jesse Skinner's approach

http://www.thefutureoftheweb.com/blog/get-redirect-after-post

Mei