How to pass input text with commas through laravel form? - php

I would like to pass string input with commas through laravel form text field. You can provide multiple numbers separated by commas, the application will handle imploding into array.
The issue is that laravel (or web browser) by default will change comma to '%2C'. I know it's a safety feature, but this is not too big concern in case of this application.
Is there a way to disable this?
Already tried to use {!! !!} instead of standard {{ }}
{{ Form::text('number', null) }}

Try using POST method in form tag instead of GET method.
It will not show field value in URL.

Related

Laravel IF Multiple values in Cookie

I have a cookie in Laravel and a variable from my server.
I want to validate the result of my server's variable with the result of the cookie.
Normally I would use this but the detail is that my server's cookie has multiple values separated by commas and inside one of them is the value I need.
#if (Cookie::get('DeliveryToken') == '{{ $orderitemaddons32 }}')
{{ Cookie::get('DeliveryToken') }}
#else
No se encontro
#endif
How do I get it to detect the comma-separated value?
I give you an example.
My variable to compare
"{{ $orderitemaddons32 }}" value = DEL-43421
"DeliveryToken" value: delton,DEL-43421,hp-32
As you can see the exact value after the first comma I need the if to parse all the values after the comma.
Or if it is in the first one to stop there and give the result of the if
A simple inline method for doing this would be convert your comma separated string into an array using explode().
Then check that the value you expect is inside that array with in_array().
For example:
in_array($check_value, explode(',', $cookie))
If this is something you frequently do, you may want to create a service to put this logic and other cookie based manipulations in.

symfony how to translate validation messages with expression

I´m trying to translate a validation message that uses expression like GreaterThan() validation constrain class.
How can I translate this message "This value should be greater than {comparator_value}." ?
Other simple messages without expression it´s working fine
thanks
If you want to to get the min value of GreaterThan. You must replace {comparator_value} with {{ compared_value }}, it will look like below:
This value should be greater than {{ compared_value }}
Hope this can help you!

Symfony form.vars.data vs form.vars.value

A FormView object in Symfony contains several variables, that can be accessed via twig using the public vars property.
Two of those variables are value and data.
So, supposing that we have our form variable in twig, we can access them using form.vars.data and form.vars.value.
The documentation is clear about the meaning of those properties:
value: The value that will be used when rendering (commonly the value HTML attribute).
data: The normalized data of the type.
but when I use {{ dump(form.vars) }} and compare form.vars.value and form.vars.data they look like identical. Why? What's the correct meaning and proper usage of those two properties?
Take for example a DateType field.
Here, value would be something like the string 2016-06-10.
data on the other hand would be a corresponding DateTime-Object.
When using Text fields, you will not see any difference because in both cases there will be just a string.

How to create a form element whose name is an array, using Blade? (Laravel-4)

I have a form which loops through an array to create the form elements, so the name of each input element must be an array element. It's easy to do this with plain old PHP:
<input type="text" name="dt[<?php echo $dues_type_id ?>]" ... />
where $dt is the array whose indices are dues types ids.
No matter what combination of quotes and curly braces I use, I cannot make this work using Blade. For example, this does not cause an error message, but it doesn't work:
{{ Form::text( 'dt[{{{ $dues_type_id }}}]', $display_amount) }}
The source code for the Blade construction is this:
<input name="dt["$dues_type_id"]" type="text">
Of course, I could just code this in PHP, but I already have all of my CSS formatting set up with Blade, and besides -- this SHOULD be possible, and I'm frustrated because I can't figure out how to do it. I'm sure I'm missing something easy... Thanks!

Laravel 4 Form Text Input

Hello I'm currently working with Laravel 4 forms. I'm struggling to generate a text input with a specific class without choosing a 'default value'. I want to do the following:
{{ Form::text('first_name', array('class' => 'first_name')) }}
However I get this error (htmlentities() expects parameter 1 to be string, array given.) unless I add a default value:
{{ Form::text('first_name', 'Some Value', array('class' => 'first_name')) }}
The default value then populates the field and needs to be deleted before entering a new value. So it can't even be used like a place holder.
Thank you in advance,
Dan
Instead of a value, supply null. (do no supply empty string "")
This will come in handy in the future if you are going to work with Form Model Binding (http://laravel.com/docs/html#form-model-binding) because null will give the value of the given model attribute.
You can pass an empty value "" like,
{{ Form::text('first_name', '', array('class' => 'first_name')) }}
Because Laravel 4's HTML Form Builder API will accept first parameter as name, second parameter as value which is null by default and the third parameter as options array which is an empty array by default.
So basically you can build text input by passing only name like,
{{ Form::text('first_name') }}
And if you are planning to pass options which is the third argument, you must pass second argument also.
See API Doc here http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#235-246
I found it better to use the Input::old('first_name') for your default value instead of just "", like:
{{ Form::text('first_name', Input::old('first_name')) }}
This way, if you go back to the form with invalid data and pass the form input, it will reload the old input that the user previously inputted. In this case, first_name is/can be bound to the first_name field in your database table as well.
Edit: Yes, the third option is an array of input options, such as text field id, size, etc. or any other HTML attribute.
Keenan :)

Categories