0

Very new to Laravel. Trying to setup a simple contact form to familiarize myself with it. I send the form data via ajax and I process each input with this in javascript:

encodeURIComponent($("#contact-name").val())

How can I run all of those inputs through

urldecode()

on the php side without having to manually do each one?

For instance I want to use this:

$this->validate($request, [
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required'
]);

and I can't because the @ in an email address gets encoded so the validation rule for valid email returns false.

I need to have all the inputs in the request run through urldecode() and then get put back so I can use all the convenient stuff Laravel has to offer.

1 Answer 1

1

just before you $this->validate(... , write following code:

foreach($request->all() as $key => $value)
{   
    $request->merge(array( $key => urldecode($value) ));
}

above foreach loop will replace all input fields with their urldecoded values.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent solution! I can't believe I missed $request's merge method after sifting through the docs. Thank You!

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.