0

In my laravel 5.7/mysql 5 app I have boolean is_quiz field in my vote Table and in model I define:

protected $casts = [
    'is_quiz' => 'boolean',
];
...

And array with possible values/keys for using of this fields

private static $voteIsQuizLabelValueArray = Array(1 => 'Is Quiz', 0 => 'Is Not Quiz');

in control I add empty value for empty selector:

$viewParamsArray['voteIsQuizValueArray']         = $this->SetArrayHeader(['' => ' -Select Is Quiz- '], Vote::getVoteIsQuizValueArray(false));

and this array has values:

$viewParamsArray['voteIsQuizValueArray']::Array
(
    [] =>  -Select Is Quiz- 
    [1] => Is Quiz
    [0] => Is Not Quiz
)

In my form this array as :

{{ Form::select('is_quiz', $voteIsQuizValueArray, isset($vote->is_quiz) ? $vote->is_quiz : '', [ "id"=>"is_quiz", "class"=>"form-control editable_field select_input " ] ) }}

and in rendered html-source I see 2 options selected :

<select id="is_quiz" class="form-control editable_field select_input valid" name="is_quiz" aria-invalid="false" aria-describedby="is_quiz-error"><option value="" selected="selected"> -Select Is Quiz- </option><option value="1">Is Quiz</option><option value="0" selected="">Is Not Quiz</option></select>

and validator.w3.org raised error here. I see what is the reson of the syntax error, but I do not know is there is easy way to fix it ?

Thanks!

mstdmstd
  • 586
  • 15
  • 39
  • 1
    Form builder is deprecated since laravel 5. Just try to build your select with blade – Roman Meyer Dec 06 '18 at 15:53
  • You are right. I have been used this library for several years, considered it very usefull and did not notice that there is no support for it any more. Is there some similar replacer of it ? Also as for my question can be any simple decision withing my model and laravel-form-builder plugin? That is live project. – mstdmstd Dec 07 '18 at 06:59
  • as far i know you can use https://packagist.org/packages/laravelcollective/html for building forms. but i don't know exactly, maybe problem with duplicating `selected` exists here too. however, i recommend you to build your select yourself, via blade with `@foreach` and `@if` – Roman Meyer Dec 07 '18 at 08:24

1 Answers1

1

Form builder is deprecated since Laravel 5

Why are Form and HTML helpers deprecated in Laravel 5.x?

As one of options you can try use Laravel Collective

https://packagist.org/packages/laravelcollective/html

But IMO the best decision is to build select via blade:

<select id="is_quiz" 
    class="form-control editable_field select_input valid" 
    name="is_quiz" 
    aria-invalid="false"
    aria-describedby="is_quiz-error"
>
    @foreach ($voteIsQuizValueArray as $k => $v)
            <option 
                    value="{{ $k }}" 
                    @if( $k === old('is_quiz', '') ) selected="selected" @endif
            >{{ $v }}</option>
    @endforeach
</select>
Roman Meyer
  • 2,634
  • 2
  • 20
  • 27