Space auto add in input php
I created a form to change data using laravel 5.1 framework, everything is fine, but when I submit the form there are two inputs, spaces are automatically added
like this screenshot
there is my form
<form method="post">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<input type="hidden" name="id_article" value="{!!$opusdef->id_article !!}">
<div class="td w10">
<input type="text" name="code_article" value="{!!$opusdef->code_article !!}" required/></div>
<div class="td w5">
<input type="text" name="num_activité" value="{!!$opusdef->num_activité !!}" required/> </div>
<div class="td w15">
<input type="text" name="libellé_activité" value="{!! $opusdef->libellé_activité !!}" required/> </div>
<div class="td w5">
<input type="text" name="domaine" value=" {{$opusdef->domaine}}" required/></div>
<div class="td w10">
<input type="text" name="s_domaine" value=" {!!$opusdef->s_domaine!!}" required/></div>
my controller
protected function postAllOpusDef(Request $request){
$data=$request->except('_token');
$opusDefs=OpusDefs::where('id_article',$data['id_article']);
if($opusDefs->update($data)){
return redirect()->back()->with('status','donnée modifiée');
};
}
+3
source to share
2 answers
You have a space in your value attribute.
Edit:
<input type="text" name="domaine" value=" {{$opusdef->domaine}}" required/></div>
<div class="td w10">
<input type="text" name="s_domaine" value=" {!!$opusdef->s_domaine!!}" required/></div>
For
<input type="text" name="domaine" value="{{$opusdef->domaine}}" required/></div>
<div class="td w10">
<input type="text" name="s_domaine" value="{!!$opusdef->s_domaine!!}" required/></div>
Also, can the user still place a space? As such, you probably want to sanitize user input before storing your data in the database.
Optionally, you can create postal data conversion middleware similar to how it works Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull
.
+3
source to share
here in html you only put two spaces in the input value
<input type="text" name="domaine" value=" {{$opusdef->domaine}}" required/></div>
<input type="text" name="s_domaine" value=" {!!$opusdef->s_domaine!!}" required/></div>
remove this like
<input type="text" name="domaine" value="{{$opusdef->domaine}}" required/></div>
<input type="text" name="s_domaine" value="{!!$opusdef->s_domaine!!}" required/></div>
+3
source to share