mercredi 5 août 2020

Form checkbox input array gets flooded with textarea input

)

I have been struggling with a form for my Laravel App.... I have 3 fields which are checkboxes and therefore is getting POSTed as arrays and then I have a textarea field and somehow SOMETIMES one of the 3 checkbox inputs get flooded with data from the textarea input field... It is very weird and only happens sometime and therefore I get a data to long truncated error in the database...

But I DD the input at the $request level and can see already there the array from the checkbox is flooded with the data from the textarea field... I can not wrap my head around why this is, as it's only sometimes... And I can even get the error and go back a page in the browser and submit again with all the same data and then it can be working.. WHAT can cause this weird behavioer

This is my Laravel blade where the form is

@extends('layouts.app')

@section('head')
@endsection

@section('content')
@php 
// dd($errors);
@endphp
<h2 class="page-title">Opret Artist Side</h2>
<div class="artist-box"> 
    <form class="formgrid" method="POST" action="">
        @csrf
        <div class="formleft">
            <label for="artist_name" class="label">Artist navn</label>
            <input type="text" id="artist_name" name="artist_name" class="formitem @error('artist_name') is-invalid @enderror" value="" />
            
            @error('artist_name')
                <div class="invalid-feedback">
                    @foreach($errors->get('artist_name') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="artist_name_help">Jeres band/artist navn. <span class="text-danger">OBS! Kan IKKE ændres</span></small>
            @enderror    
        </div>

        
        <div class="formright">
            <label for="contact_person" class="label">Kontakt person</label>
            <input type="text" name="contact_person" id="contact_person" class="formitem @error('contact_person') is-invalid @enderror" value="" />
            
            @error('contact_person')
                <div class="invalid-feedback">
                    @foreach($errors->get('contact_person') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="contact_person_help">Kontakt persons navn</small>
            @enderror    
        </div>
            

        <div class="formleft">
            <label for="email" class="label">Email</label>
            <input type="text" name="email" id="email" class="formitem @error('email') is-invalid @enderror" value="" />
            
            @error('email')
                <div class="invalid-feedback">
                    @foreach($errors->get('email') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="email_help">Kontakt email</small>
            @enderror
        </div>


        <div class="formright">
            <label for="phone" class="label">Tlf nummer</label>
            <input type="text" name="phone" id="phone" class="formitem @error('phone') is-invalid @enderror" value="" />
            
            @error('phone')
                <div class="invalid-feedback">
                    @foreach($errors->get('phone') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="phone_help">Kontakt tlf nummer</small>
            @enderror
        </div>

        
        <div class="formleft">
            <label for="hometown" class="label">Hjemby</label>
            <input type="text" name="hometown" id="hometown" class="formitem @error('hometown') is-invalid @enderror" value="" />
            
            @error('hometown')
                <div class="invalid-feedback">
                    @foreach($errors->get('hometown') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="hometown_help">Jeres Hjemby</small>
            @enderror
        </div>


        <div class="formright">
            <label for="category" class="label">Kategori</label>
            <select name="category" id="category" class="formitem @error('category') is-invalid @enderror">
                
                @if(old('category') === null)
                    <option disabled="disabled" selected value="null">Vælg en kategori</option>
                @endif
                
                @foreach($categories as $category)
                    <option @if(old('category') !== null && old('category') == $category->id) selected @endif value=""
                        ></option>
                @endforeach
            </select>
            
            @error('category')
                <div class="invalid-feedback">
                    @foreach($errors->get('category') as $error)
                        
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="">Hvilken kategori hører i under</small>
            @enderror
        </div>

        
        <div class="formfull">
            <label for="budget" class="label">Budget i spiller for</label>
            <ul class="ks-cboxtags">
            @foreach($budgets as $budget)
                
                <li><input @if(old('budget') !== null && in_array($budget->id,old('budget'))) checked @endif
                type="checkbox" name="budget[]" id="budget" class="form-check-input @error('budget') is-invalid @enderror" value="" />
                <label class="form-check-label" for="budget"></label></li>
                
            @endforeach
            </ul>
            
            @error('budget')
                <div class="invalid-feedback d-block">
                    @foreach($errors->get('budget') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="budget_help">Vælg hvilket budget i optræder for, gerne flere</small>
            @enderror           
        </div>
        
        
        <div class="formfull">
            <label for="genres" class="label">Genre</label>
            <ul class="ks-cboxtags">
            @foreach($genres as $genre)
                
                <li><input @if(old('genres') !== null && in_array($genre->id,old('genres'))) checked @endif
                type="checkbox" name="genres[]" id="genres" value="" class="form-check-input @error('genres') is-invalid @enderror" />
                <label class="form-check-label" for="genres"></label></li>
                
            @endforeach
            </ul>
            
            @error('genres')
                <div class="invalid-feedback d-block">
                    @foreach($errors->get('genres') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="">Hvike genrer hører i under</small>
            @enderror           
        </div>
        

        <div class="formfull">
            <label for="area" class="label">Områder hvor i optræder</label>
            <ul class="ks-cboxtags">
            @foreach($areas as $area)
                
                <li><input @if(old('area') !== null && in_array($area->id,old('area'))) checked @endif
                type="checkbox" name="area[]" id="area" value="" class="form-check-input @error('area') is-invalid @enderror" />
                <label class="form-check-label" for="area"></label></li>
                
            @endforeach
            </ul>
            
            @error('area')
                <div class="invalid-feedback d-block">
                    @foreach($errors->get('area') as $error)
                    
                    @endforeach
                </div>
            @else 
                <small class="text-muted form-text" id="">Vælg hvilke områder i optræder i</small>
            @enderror           
        </div>

     
        <div class="formleft">
            <label for="desc" class="label">Beskriv jer selv</label>
            <textarea name="description" id="description" class="formitem @error('description') is-invalid @enderror"></textarea>
            
            " class="form-control @error('description') is-invalid @enderror" name="description" type="hidden">
            @trix(\App\ArtistPage::class, 'trixinput',
            [
            'id' => 'description',
            // 'class' => 'form-control',
            'hideTools' => ['file-tools'],
            'hideButtonIcons' => ['attach', 'link', 'code', 'strike', 'heading-1']
            ]) --}}
            
            " type="hidden" name="description">
            <trix-editor input="desc" class="@error('description') is-invalid @enderror"></trix-editor> --}}
            @error('description')
                <div class="invalid-feedback">
                    @foreach($errors->get('description') as $error)
                    
                    @endforeach
                </div>
            @else 
            <small class="text-muted form-text" id="description_help">Giv en god beskrivelse af jer selv og hvad i tilbyder<br>
                Tilladte tags er <strong><br><b><i><li><ul><ol><hr><strong><p></strong>
            </small>
            @enderror           
        </div>


        <button type="submit" class="btn btn-primary">Opret</button>
    </form>
</div>

    @endsection

See also this image of the DD dump on the $request

enter image description here




Aucun commentaire:

Enregistrer un commentaire