Welcome Guest, Not a member yet? Register   Sign In
DRY approach with different request type
#4

Well what behavior do you want when it fails to validate? Do you want the page which sent the ajax request to show an error message, or to redirect to another page?

Either way, you would need to return the response you want (either an error message which you can then display, or a url to redirect to, which you can do with Javascript). Return a JSON response containing the relevant info and in the callback for the ajax call, do whatever you need to do with it.

So this outputting might be something like:

PHP Code:
//Set response variables you need
$response['success'] = false;
$response['message'] = "Validation error";
$response['redirect'] = "/error";

//Output json response
$this->output
 
->set_content_type('application/json')
 ->
set_output(json_encode($response))
 ->
_display();

exit; 

For non-ajax requests, you can just use the PHP redirect function.
Reply


Messages In This Thread
RE: DRY approach with different request type - by JayAdra - 10-18-2016, 06:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB