0

i´m trying to validate a form in laravel 4 with Jquery Validator, the only thing i can´t perform it´s a remote validation for the email.

I tried with my browser the following

http://example.com/validacion/email/[email protected] 

and i get the result (in json) that i want.

//Routes.php 
Route::get('validacion/email/{email}', 'ValidatorController@getValidacionEmail');

//In my JS the rule of email is
         email: {
            required: true,
            email: true,
            remote: {
                url: "/validacion/email/",
                type: "get",
                data: {
                    email: "[email protected]"
                },
                complete: function(data) {
                    if (data.responseText !== "true") {
                        alert(data.respuesta);
                    }
                }
         }

And when i use Firebug I get this location

http://example.com/validacion/email/?email=akatcheroff%40gmail.com

and a 301 code and after that a 500 and this error

{"error":{"type":"Symfony\Component\HttpKernel\Exception\NotFoundHttpException","message":"","file":"C:\Users\Usuario\Dropbox\Public\sitios\futbol\vendor\laravel\framework\src\Illuminate\Routing\Router.php","line":1429}}

Does anybody knows if there is a way to send my mail parameter in a way that the route recognize it?

Thanks!

1
  • Try removing trailing slash at the end of your ajax url url: "/validacion/email", and remove the {email} parameter on your route. Commented Sep 29, 2013 at 7:32

1 Answer 1

3

Problem

The route you have specified validacion/email/{email} will handle routes such as:

(1) http://mysite.com/validacion/email/[email protected] (Just like you tried in Firefox.)

When your ajax runs you end up (just as firebug dumped) with urls such as:

(2) http://mysite.com/validacion/email/[email protected]

Now notice the difference between url 1 and 2. The first one have the email value as a segment of the url. The second have the email value as part of the query string.

The error Laravel throws is saying that the router couldn't find a matching handler for the url.

Solutions

You can solve this by either changing your javascript:

remote: {
    url: "/validacion/email/" + "[email protected]",
    type: "get"
}

Remove the email from the query string and add it to the path.

Or, you can solve it by changing your PHP route:

Route::get('validacion/email', 'ValidatorController@getValidacionEmail');

Then in getValidacionEmail you can get the email from the query string using:

$email = Input::get('email');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.