cakephp url validation - validation

One of my models has a 'url' field. I am using the default url validation rule on it. When trying to add a specific url it is not validated.
The url causing validation to fail is http://careers2.hiredesk.net/ViewJobs/JobDetail.asp?Comp=I3&TP_ID=1&PROJ_ID={BDA01FCD-5703-4D40-9197-CCF688633951}
The { character is causing the validation to fail. What workarounds do I have here?

Do you pass your given URL through a URL Encode Function first? See the linked page for an example.

Related

Laravel 5.6 ERR_TOO_MANY_REDIRECTS on GET request

I have a custom Request class which deals with the validation of a form. This form uses 'GET' and will filter down all the results the User can see on the page.
My rule for the start date:
'date_start' => 'nullable|date|required_with:date_end',
is causing a message:
ERR_TOO_MANY_REDIRECTS
My controller looks like this:
public function index (ApprovedSubmissionsFilterRequest $request)
{
...
I believe that this is because when the validation fails, it sends a GET request back to the index method, which once more fails the validation and redirects back to the index method etc. etc.
How do I avoid this loop? I do not want to use a POST request instead of a GET.
Here is my route:
Route::get('formSubmission', 'FormSubmissionController#index')
->name('formSubmission.index');
Thank you.
NOTE (edit):
Not all validation errors cause this - it only seems to be the required_with that is causing the issue. Somebody has mentioned it here previously.
I tried your code in my project, and cannot reproduce the problem. So do you really use the correct validation rule, because from the docs, the required_with takes an effect only if the other field that you are trying to validate exists in the request. So in your case date_start should not be present in the request and date_end should exist in order for this validation to take place:
required_with:foo,bar,...
The field under validation must be present and not empty only if any of the other specified fields are present.
Also from the github issue that you have mentioned, you can debug in the exception handler what happens when ValidationException is thrown
Your last note, have you tried with all validation rules except that one if it passes?

Validation for file types not working in laravel 4

After lots of search and no luck to found the solution.
I am validating a input file in laravel 4.2.*. Using the model validation rules but rules not working for me.
rules i am using in my model.php
'reqfile' => 'mimes:txt,pdf,doc,docx|max:20000'
and
'reqfile' => 'mimes:application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,application/pdf|max:20000'
After applying these rules the validation errors generated but the errors also appear on the valid file selection.
Here's anybody tells me, where i am wrong to apply the rules.
Thanks in Advance.
For this validator rule to work you need to make sure that the value being validated for reqfile is an instance of:
Symfony\Component\HttpFoundation\File\File
or
Symfony\Component\HttpFoundation\File\UploadedFile
So if you're validating a form, reqfile must be a uploaded file. That means its value should come from Input::file(). So your validator should look something like this:
Validator::make(
// Value for reqfile
array('reqfile' => Input::file('reqfile')),
// Validator rule for reqfile
array('reqfile' => 'mimes:txt,pdf,doc,docx|max:20000')
);
The validation rule will actually try to guess the extension by extracting the mime type and compare that to the extension list passed into the rule. That means that you need to pass file extensions to the rule, not actual mime types, as the documentation clearly states:
The file under validation must have a MIME type corresponding to one of the listed extensions

Codeigniter URL routing solution for my website

I have a website that is developed with CodeIgniter. I have added the route for my url as follows:
$route['about_us'] = 'about-us';
Now I have a problem with that. I.e. when I am looking for the url www.mysite.com/about_us it works and at same time www.mysite.com/about-us is also working. I want only one url to work: the one with the underscore.
I have removed this to:
$route['about_us'] = 'about-us';
But the url www.mysite.com/about-us still works. It may cause duplicate content for my website in Google and so more page links also showing. Even I don't have that functions too. Like www.mysite.com/about_us/design. Likewise in about_us controller file index function only there, but design method calling in Google.
How do I resolve this problem?
You actually don't need a route here. The normal purpose of request routing the way you are using it is so that you can use hyphenated URLs when hyphens are not permitted in class and function names. I.E. you want the url to by www.example.com/test-controller, but you can't actually name a controller test-controller because the hyphen is illegal.
If you only want to have the underscored URL such as www.mysite.com/about_us then just remove the route completely and name the controller about_us. With no routing rules the hyphenated url should 404.

Make the route parameter actually appear in the address bar

I have a tiny application in MVC 3.
In this tiny application, I want my URLs very clear and consistent.
There's just one controller with one action with one parameter.
If no value is provided (that is, / is requested by the browser), then a form is displayed to collect that single value. If a value is provided, a page is rendered.
The only route is this one:
routes.MapRoute(
"Default",
"{account}",
new { controller = "Main", action = "Index", account = UrlParameter.Optional }
);
This all works fine, but the account parameter never appears in the address line as a part of the URL. I can manually type test.com/some_account and it will work, but other than that, the account goes as a post parameter and therefore does not appear. And if I use FormMethods.Get in my form, I get ?account=whatever appended to the URL, which is also not what I want and which goes against my understanding. My understanding was that the MVC framework would try to use parameters set in the route, and only if not found, it would append them after the ?.
I've tried various flavours of setting the routes -- one route with a default parameter, or one route with a required parameter, or two routes (one with a required parameter and one without parameters); I've tried mixing HttpGet/HttpPost in all possible ways; I've tried using single action method with optional parameter string account = null and using two action methods (one with parameter, one without), but I simply can't get the thing appear in the URL.
I have also consulted the Steven Sanderson's book on MVC 3, but on the screenshots there are no parameters either (a details page for Kayak is displayed, but the URL in the address bar is htpp://localhost:XXXX/).
The only thing that definitely works and does what I want is
return RedirectToAction("Index", new { account = "whatever" });
But in order to do it, I have to first check the raw incoming URL and do not redirect if it already contains an account in it, otherwise it is an infinite loop. This seems way too strange and unnecessary.
What is the correct way to make account always appear as a part of the URL?
My understanding was that the MVC framework would try to use
parameters set in the route, and only if not found, it would append
them after the ?
Your understanding is not correct. ASP.NET MVC doesn't append anything. It's the client browser sending the form submission as defined in the HTML specification:
The method attribute of the FORM element specifies the HTTP method used
to send the form to the processing agent. This attribute may take two
values:
get: With the HTTP "get" method, the form data set is appended to the URI specified by the action attribute (with a question-mark ("?")
as separator) and this new URI is sent to the processing agent.
post: With the HTTP "post" method, the form data set is included in the body of the form and sent to the processing agent.
ASP.NET MVC routes are used to parse an incoming client HTTP request and redispatch it to the corresponding controller actions. They are also used by HTML helpers such as Html.ActionLink or Html.BeginForm to generate correct routes. It's just that for your specific scenario where you need to submit a user entered value as part of the url path (not query string) the HTML specification has nothing to offer you.
So, if you want to fight against the HTML specification you will have to use other tools: javascript. So you could use GET method and subscribe to the submit handler of the form and inside it manipulate the url so the value that was appended after the ? satisfy your requirements.
Don't think of this as ASP.NET MVC and routes and stuff. Think of it as a simple HTML page (which is what the browser sees of course) and start tackling the problem from that side. How would you in a simple HTML page achieve this?

Can I have multiple inputs in a form in CodeIgniter URL?

I know that CodeIgniter already elegantly handles URL's. What I have is a form with multiple elements (date, keyword, location = optional). Is it possible to set up CI to create a URL that looks like:
mysite.com/class/function/date/keyword?
If you are using CodeIgniter's form helper, it sends your form data via POST, so you can't easily have your field's value displayed in the url.
What you could have, though, is a controller method that collects your form data and redirects to the url you want.
If you need further clarification, please let me know.
Yes, you can use the anchor function by passing the relevant info to it.

Resources