Welcome Guest, Not a member yet? Register   Sign In
Form validation with redirect
#9

(This post was last modified: 10-27-2015, 12:21 PM by Martin7483.)

What is the url to your form? I'm assuming it is /home and your post url is /home/send. If this is the case then you are defining you rules in the send method and you then validate your posted form.

Define your rules in the home method and do your validation in your home method. Your post URL would then be /home#anchor instead of /home/send. If the validation fails, the view with your form and errors is loaded and the #anchor wil take you to your form. No need for JavaScript.

If the form passed validation you could redirect to your send method and save the post dataset in a flashdata for processing in your send method.

PHP Code:
class Home extends CI_Controller {
 
   
    public 
function home() {
 
       if ($this->form_validation->run() == FALSE) {
 
           $data['post_url'] = '/home#anchor';
 
           $this->load->view('yourform'$data);
 
       } else {
 
           $this->session->set_flashdata('yourform'$this->input->post());
 
           redirect(base_url('home/send'));
 
       }
 
   }
 
   
    public 
function send() {
 
       // If your flashdata item is not set NULL is returned
        
$post $this->session->flashdata('yourform');
        if( ! 
is_null($post) ) {
 
           // Do what you want to do with your post dataset
 
       } else {
 
           // The form has already been processed
 
           $this->load->view('form_already_processed');
 
       }
 
   }


Maybe my example can help you on your way. In my example the problem of double form posting is also solved
Reply


Messages In This Thread
Form validation with redirect - by msheath - 10-26-2015, 04:42 AM
RE: Form validation with redirect - by Martin7483 - 10-26-2015, 05:34 AM
RE: Form validation with redirect - by msheath - 10-26-2015, 07:26 AM
RE: Form validation with redirect - by Martin7483 - 10-26-2015, 07:44 AM
RE: Form validation with redirect - by msheath - 10-26-2015, 08:09 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 02:39 AM
RE: Form validation with redirect - by Narf - 10-27-2015, 03:42 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 02:54 AM
RE: Form validation with redirect - by Narf - 10-28-2015, 04:21 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 04:50 AM
RE: Form validation with redirect - by Martin7483 - 10-27-2015, 12:16 PM
RE: Form validation with redirect - by msheath - 10-28-2015, 02:15 AM
RE: Form validation with redirect - by mwhitney - 10-27-2015, 12:29 PM
RE: Form validation with redirect - by Martin7483 - 10-28-2015, 02:41 AM
RE: Form validation with redirect - by Martin7483 - 10-28-2015, 05:00 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 05:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB