For some time I have a strange issue:
with standard syntax
{{Form :: radio ('somename', 'someval', true, ['adparam' => 'someparam'])}}
the parameter 'checked' does not render on the local host (mac, vagrant / box, laravel 5.4), but it works on a remote server ...
I have already broken the brain, in which direction to dig since I did not even notice the moment when it started work incorrectly (in fact, it worked some time ago)?
UPD:
A whole page is realy big, but the piece of code is
{{ Form::radio('certain', '1', true, ['data-case'=>$case->slug]) }} Возможный
{{ Form::radio('certain', '2', false, ['data-case'=>$case->slug]) }} Вероятный
{{ Form::radio('certain', '3', false, ['data-case'=>$case->slug]) }} Характерен для
{{ Form::radio('certain', '4', false, ['data-case'=>$case->slug]) }} Достоверный/Верифицированный
In fact, the issue shows up only when data in the controller matches with a view. If I have $case->certain and radio certain it does not work, but when I change radio name on some like certain2 it works but has no sense, of course. As I mentioned the issue exists only on localhost and just disturb to develop.
UPD:
After fighting with debugging tools I have found that servers handle param in different ways.
For localhost works:
{!! Form::radio('sex', 0, true) !!}
{!! Form::radio('sex', 1) !!}
{!! Form::radio('sex', 2) !!}
For production works:
{!! Form::radio('sex', '0', true) !!}
{!! Form::radio('sex', '1') !!}
{!! Form::radio('sex', '2') !!}
The Question: where is hidden a setting for this (etc 1!='1')?
You can't have multiple radio buttons selected. Radio button groups allow a single selection. You need checkboxes in order to accomplish multiple selections.
The issue comes down to using different database PDO drivers.
Some return ints as strings, others return it as an int. More here
Temp solution is
'mysql' => [
'options' => [PDO::ATTR_EMULATE_PREPARES => true]
],
in config in database.php
Related
I'm using laravel 9. I have stored data using summer note in the database, but it shows empty or null when I retrieve data from the database.
here is my code.
{!! Str::of($item->product_description)->limit(40) !!}
Try this
{!! Str::limit($item->product_description,40) !!}
I am running a Laravel app on heroku and built a multi step form, that updates the object on every step. I also make use of the HTML library, which assists me in creating the forms, see my code below. Now I realized, that the model binding for selects is not working, when I open the form later. Instead, the first option of the array of options is displayed as default.
However, this only happens on production environment (heroku) and not on my local xampp server. Furthermore, model binding works in production on numbers or strings, only selects don't bind correctly.
I also tested, that the object has the correct value so it's not a database saving error and everything works fine.
Review my code below:
// Form is opened here
{!! Form::model($umzug, ['method'=>'PUT', 'action' => array('UmzugController#update', $umzug->id)]) !!}
...
<div class="col-sm-6">
{!! Form::label('halteverbot_auszug', 'Halteverbot') !!}
// Following line prints 'N', as it was selected previously and was therefore saved correctly in the DB
{{ $umzug->halteverbot_auszug }}
// Following line should produce a select input with 'Nein' selected, but shown 'Ja' instead
{!! Form::select('halteverbot_auszug', ['J' => 'Ja', 'N' => 'Nein'], null, ['class'=>'form-control', 'id'=>'halteverbot_auszug']) !!}
</div>
...
{!! Form::close() !!}
As the code is the same in production and on local, I have no clue how it can produce different outcomes, but I would be glad to hear any suggestions on how I can fix it.
Thanks in advance!
I was able to resolve the issue, by using 0 and 1 instead of 'J' and 'N'. I assume, that the different database types (mysql locally and postgresql on heroku) are handling characters different and second not as well as the first. Using integers instead fixed my problem.
I have this form.
{!! Form::open(['action' => 'ArticlesController#store', 'method' => 'post', 'enctype' => 'multipart/form-data']) !!}
<div class="form-group">
Form::select('size', array(
'L' => 'Large',
'S' => 'Small'
));
</div>
{!! Form::close() !!}
The user will have a dropdown list to select Large (value: L) or Small (value: S). But if the user, let say, changes the value of any of those options using the dev tools, or whatever.
How can I validate the form if the user sends the 'size' field with a value that wasn't originally in the select options?
I mean, how can I check that the sent value is L or S, but not anything else.
Because the user could easily edit the form and send whatever value he wants to send, he could send a value that wasn't suppose to be sent.
I can do that using the validate class, but if instead of a 2 options list it is a 100 options list that'd be impossible.
Thanks!
This is how you can validate that:
$request->validate(['size' => 'required|in:L,S']);
this part after pipe "|in:L,S'" is used to check if the $request attribute value is equal to any value in that rule.
https://laravel.com/docs/5.5/validation#rule-in
Is there some way to insert a blank option when creating a select input with the Laravel FormBuilder? I have this at the moment but I want to change it
{!! Form::select('tipo_id', ['blank' => ''] + $tipos, null, ['class' => 'form-control']) !!}
You cannot do too much better than you are already doing. Secret is to have array first element empty to show blank input.
So I am now working with the update part of my program, now i want to populate my forms with the older records from my database to edit it. Now my problem is the radio button, how can select the true one. I tried this code, i use if on my radio buttons
{{ Form::label('Type','Type')}}
{{ Form::radio('ctype', '1',if(($item->bname)==1){true}) }}
{{ Form::label('Rooster','Rooster')}}
{{ Form::radio('ctype', '0') }}
{{ Form::label('Hen','Hen')}}
But I just get error 500, please help
In the documentation it says:
echo Form::radio('name', 'value', true);
So you should go this way:
{{ Form::radio('ctype', '1', $item->bname == 1) }}
You shouldn't need any additional brackets. Third param is a simple boolean value.