Welcome Guest, Not a member yet? Register   Sign In
How to redirect on form validation succes?
#12

[eluser]Dyllon[/eluser]
In your process function you are successfully returning validation errors with json, you need to return a success message the same way with json.
Then in your jquery callback function check your data to determine if it's validation errors or a saved record and redirect or display errors as necessary.

Untested:
Code:
function process() {
    $this->load->helper('jsonwrapper');
    $this->load->helper('url');
    $this->load->library("validation");
    if ($this->validation->run() == FALSE) {
        $data = array(
                'fname' => $this->validation->fname_error,
                'lname' => $this->validation->lname_error
        );
          
        echo json_encode($data);
    } else {
        $data = array(
                'fname' => $this->input->post("fname"),
                'lname' => $this->input->post("lname"),
                'success' => TRUE
        );
        echo json_encode($data);          
    }

}

Code:
$(document).ready(function() {
    $("#form").submit(function() {
        var fname= $("#fname").val();
        var lname= $("#lname").val();
        $.post("/welcome/process", { fname:fname, lname:lname },
        function(data){
            if(data.success == TRUE) {
                [removed] = BASE_URI + 'welcome';
            }
            else {
                $("#fname_error").html(data.fname);
                $("#lname_error").html(data.lname);
            }
        },'json');
    });
});


Messages In This Thread
How to redirect on form validation succes? - by El Forum - 01-09-2010, 12:21 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 12:57 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 01:10 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 01:14 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 01:22 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 04:31 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 07:59 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 08:29 PM
How to redirect on form validation succes? - by El Forum - 01-09-2010, 08:32 PM
How to redirect on form validation succes? - by El Forum - 01-10-2010, 02:55 AM
How to redirect on form validation succes? - by El Forum - 01-10-2010, 01:24 PM
How to redirect on form validation succes? - by El Forum - 01-10-2010, 03:04 PM
How to redirect on form validation succes? - by El Forum - 01-11-2010, 05:37 AM
How to redirect on form validation succes? - by El Forum - 01-11-2010, 12:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB