this code is ok with text inputs
<input value="{{ old('YOM') }}" id="YOM" class="form-control" type="year" name="YOM" id="">
but want add old data to select tag s and also radio buttons
<select id="condition" name="condition" class=" form-control" >
<option value="" >Select Condition</option>
<option value="Brand New" >Brand New</option>
<option value="Recondition" >Recondition</option>
<option value="Used" >Used</option>
</select>
<input type="checkbox" name="SaleOrRent" value="Sell">Sell <span></span>
<input type="checkbox" name="SaleOrRent" value="Rent">Rent
<input type="checkbox" name="SaleOrRent" value="Sell or Rent">Sell or Rent
You could do this.
<select id="condition" name="condition" class=" form-control" >
<option value="" >Select Condition</option>
<option value="Brand New" {{ old('condition') === 'Brand New' ? 'selected' : '' }} >Brand New</option>
<option value="Recondition" {{ old('condition') === 'Recondition' ? 'selected' : '' }} >Recondition</option>
<option value="Used" {{ old('condition') === 'Used' ? 'selected' : '' }} >Used</option>
</select>
<input type="checkbox" name="SaleOrRent" value="Sell" {{ old('SaleOrRent') === 'Sell' ? 'checked' : '' }} >Sell <span></span>
<input type="checkbox" name="SaleOrRent" value="Rent" {{ old('SaleOrRent') === 'Rent' ? 'checked' : '' }} >Rent
<input type="checkbox" name="SaleOrRent" value="Sell or Rent" {{ old('SaleOrRent') === 'Sell or Rent' ? 'checked' : '' }} >Sell or Rent
<option value="{{old('condition'}}" >Select Condition</option>
and for the radio:
<input type="checkbox" name="SaleOrRent" value="{{old('saleOrRent)}}">Sell <span></span>
Related
I can successfully get input session data on another page but I can't get select menu selected data in another page.
This is my first form
<form action="{{ route('admin.create.step.one.post') }}" method="POST">
#csrf
<label for=""> Student Name </label>
<input type="text" name="student_name" value="{{ $report->student_name ?? '' }}">
<br>
<label for=""> Email </label>
<input type="text" name="student_email" value="{{ $report->student_email ?? '' }}">
<br>
<label for=""> Phone number </label>
<input type="text" name="student_phone" value="{{ $report->student_phone ?? '' }}">
<label for=""> Group </label>
<select name="group" id="">
<option value="1" {{ $report->group ?? '' }}> Science </option>
<option value="2" {{ $report->group ?? '' }}> Arts </option>
</select>
<button type="submit"> Preview </button>
</form>
I want to get session data in this page.
I can't get select menu session data.
<form action="">
#csrf
<table>
<td> {{ $report->student_name }} </td>
<td> {{ $report->student_email }} </td>
<td> {{ $report->student_phone }} </td>
<td> {{ $report->group }} </td>
</table>
</form>
As far as I understood from your question you want to select the item within your select input.
You are just missing this line:
{{ $report->group == 1 ? 'selected' :'' }}
<form action="{{route('admin.create.step.one.post')}}" method="POST">
#csrf
<label for="student_name">Student Name</label>
<input type="text" name="student_name" id="student_name" value="{{ $report->student_name}}">
<br>
<label for="student_email">Email</label>
<input type="text" name="student_email" id="student_email" value="{{ $report->student_email}}">
<br>
<label for="student_phone">Phone number</label>
<input type="text" name="student_phone" id="student_phone" value="{{ $report->student_phone}}">
<br>
<label for="group">Group</label>
<select name="group" id="group">
<option value="1" {{ $report->group == 1 ? 'selected' :'' }}>Science</option>
<option value="2" {{ $report->group == 2 ? 'selected' :'' }}>Arts</option>
</select>
<button type="submit">Preview</button>
</form>
Now, if you need are storing in the session() something and not getting it please update your question with your Controller and I will update my answer to help you further.
I see that you want to get the selected item when you submitted and an error appeared so if you want to get the old value
you can do so using old() method in your blade.
{{ old('group') == 1 ? 'selected' :'' }}
<form action="{{route('admin.create.step.one.post')}}" method="POST">
#csrf
<label for="student_name">Student Name</label>
<input type="text" name="student_name" id="student_name" value="{{ $report->student_name}}">
<br>
<label for="student_email">Email</label>
<input type="text" name="student_email" id="student_email" value="{{ $report->student_email}}">
<br>
<label for="student_phone">Phone number</label>
<input type="text" name="student_phone" id="student_phone" value="{{ $report->student_phone}}">
<br>
<label for="group">Group</label>
<select name="group" id="group">
<option value="1" {{ old('group') == 1 ? 'selected' :'' }}>Science</option>
<option value="2" {{ old('group') == 2 ? 'selected' :'' }}>Arts</option>
</select>
<button type="submit">Preview</button>
</form>
I got the code snippet,
<div class="form-group">
<label for="category-id-field">Category</label>
<select class="form-control" name="category_id" id="category-id-field">
<option value="" hidden disabled {{ $topic->id ? '' : 'selected' }}>Choose your category</option>
#foreach ($categories as $value)
#php
$selected = $topic->category_id === $value->id ? 'selected' : '';
#endphp
<option value="{{ $value->id }}" {{ $selected }}>{{ $value->name }}</option>
#endforeach
</select>
</div>
And it shows like below, as you can see $value->name works but $value->id just shows up zero.
<div class="form-group"><label for="category-id-field">Category</label>
<select name="category_id" id="category-id-field" class="form-control">
<option value="" selected="selected">Choose your category</option>
<option value="0">statement</option>
<option value="0">life</option>
<option value="0">work</option>
<option value="0">study</option>
</select>
</div>
Versions:
laravel/framework: "^7.0"
Platform: macos catalina
mysql: 8.0.19
Some more background:
Things I did, the id in the categories table used to be integer, I changed it to VARCHAR(30) and added it as the foreign key to table topics->category_id.
If anyone happens to have some experience on this one, please point out the error. Many thanks.
After much research on this forum, but elsewhere on the Internet, "Cat got your tongue".
Many messages speak about this subject, but I can not correct my mistake on my side.
I use the same form to add or modify my data.
I have an error with my form only when I want to modify my data.
Wep.app :
// Gérer les personnes (sociétés, personnes...) photographiées
Route::get('tiers', 'tiersController#afficheliste'); // Fait
Route::get('tiersajouter', 'tiersController#ajouter'); // Fait
Route::post('tiersmodifier', 'tiersController#modifier'); // Fait
Route::post('tiersupdatesql', 'tiersController#updatesql'); // Fait
Route::post('tierssupprimer', 'tiersController#supprimer'); // Fait
Route::post('tiersreactiver', 'tiersController#reactiver'); // Fait
ctrltiersRequest :
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ctrltiersRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize() {
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules() {
return [
'tiersNom' => 'required|min:5',
'ville' => 'required',
'tiersiptc1' => 'required',
'tiersiptc2' => 'required'
];
}
public function messages() {
return [
'tiersNom.required' => "Le nom est obligatoire",
'tiersNom.min' => "Le nom doit faire au minimum 5 caractères",
'ville.required' => "La ville est obligatoire",
'tiersiptc1.required' => "Le thème principal est obligatoire",
'tiersiptc2.required' => "Le sous-thème est obligatoire"
];
}
}?>
tiersModif.blade :
I can not paste the contents of my blade file into this message. I add it in a reply to this message. I am sorry...
tiersControllers :
public function updatesql(ctrltiersRequest $request) {
//public function updatesql(tiersRequest $request) {
//['tiers_id' => (int)$request->tiersModif],
$tiers = tiers::updateOrCreate(
['tiers_id' => $request->tiersModif],
['tiers_nom' => $request->tiersNom,
'tiers_prenom' => $request->tiersPrenom,
'tiers_societeproduction' => $request->production,
'tiers_ville' => $request->ville,
'tiers_iptc1' => $request->tiersiptc1,
'tiers_iptc2' => $request->tiersiptc2,
'tiers_iptc3' => $request->tiersiptc3]);
// Afficher
return Redirect('tiers');
The contents of the blade file:
#extends('layouts.app')
#section('style')
<link href="{{ asset('css/grid.css') }}" rel="stylesheet">
<style>
body {
padding-top: 50px;
}
.navbar-template {
padding: 40px 15px;
}
</style>
#endsection
#section('bardemenu')
#include('menu')
#endsection
#section('contenu')
#if ( $Action['Action'] == "Ajouter" )
<h4> Ajouter un tiers (artiste, photographe, club...)</h4>
#if ($errors->any())
<ul>{!! implode('', $errors->all('<li style="color:red">:message</li>')) !!}</ul>
#endif
<form method="POST" action="{!! url('tiersupdatesql') !!}" accept-charset="UTF-8">
<label for="Nom">Nom : </label><input name="tiersNom" type="text" id="tiersNom" maxlength="50" size="50"><br>
<label for="Prenom">Prénom : </label><input name="tiersPrenom" type="text" id="tiersPrenom" maxlength="50" size="50"><br>
<label for="Production">Société de production : </label><input type="radio" name="production" value="0" checked> Non (par défaut) <input type="radio" name="production" value="1"> Oui<br>
#if ( $boiteprod->count()==0 )
<label for="Production">Pas de boite de production dans la base.</label>
#else
<label for="Production">Manager par la boite de production : </label>
<select name="production" id="production">
<option value="">--- choisir une boite de production ---</option>
#foreach ($boiteprod as $bprod)
<option value="{{ $bprod->tiers_id }}">{{ $bprod->tiers_nom }} {{ $bprod->ville_name }} ({{ $bprod->zip_code }})</option>
#endforeach
</select>
#endif
<br>
<label for="ville"> Ville : </label>
<select name="ville" id="ville">
<option value="">--- choisir une ville ---</option>
#foreach ($villes as $ville)
<option value="{{ $ville->ville_id }}">{{ $ville->ville_name }} ({{ $ville->zip_code }}), {{ $ville->namedept }}-{{ $ville->nom_fr_fr }}</option>
#endforeach
</select><br>
<label for="tiersIPTC1">Thème : </label>
<select name="tiersiptc1" id="tiersiptc1">
<option value="0">Choisissez un thème principal</option>
#foreach ($iptc1s as $iptc1)
#if( !empty($MetadataSeance[0]->metadata_Id) )
<option value="{{ $iptc1->IPTC1_Id }}" {{ ($iptc1->IPTC1_NomFR==$MetadataSeance[0]->comadobecategory) ? "selected=selected" : '' }}>{{ $iptc1->IPTC1_NomFR }}</option>
#else
<option value="{{ $iptc1->IPTC1_Id }}">{{ $iptc1->IPTC1_NomFR }}</option>
#endif
#endforeach
</select><label for="tiersIPTC2">, </label>
<select name="tiersiptc2" id="tiersiptc2">
<option value="0">---</option>
#foreach ($iptc2s as $iptc2)
#if( !empty($MetadataSeance[0]->metadata_Id) )
<option value="{{ $iptc2->IPTC2_Id }}" CLASS="{{ $iptc2->IPTC2_IPTC1 }}" {{ ($iptc2->IPTC2_Numero==$MetadataSeance[0]->comadobeiptcSubjectCode ) ? "selected=selected" : '' }}>{{ $iptc2->IPTC2_NomFR }} ({{ $iptc2->IPTC2_Numero }})</option>
#else
<option value="{{ $iptc2->IPTC2_Id }}" CLASS="{{ $iptc2->IPTC2_IPTC1 }}">{{ $iptc2->IPTC2_NomFR }} ({{ $iptc2->IPTC2_Numero }})</option>
#endif
#endforeach
</select><label for="tiersIPTC3">, </label>
<select name="tiersiptc3" id="tiersiptc3">
<option value="">---</option>
#foreach ($iptc3s as $iptc3)
<option value="{{ $iptc3->IPTC3_Id }}" CLASS="{{ $iptc3->IPTC3_IPTC2 }}">{{ $iptc3->IPTC3_NomFR }}</option>
#endforeach
</select>
<br>
{!! csrf_field() !!}
<input type="hidden" name="action" id="action" value="{{ $Action['Action'] }}">
<input type="submit" value="Ajouter">
Annuler
</form>
#else
<h4> Mettre à jour un tiers (artiste, photographe, club...)</h4>
#if ($errors->any())
<ul>{!! implode('', $errors->all('<li style="color:red">:message</li>')) !!}</ul>
#endif
<form method="POST" action="{!! url('tiersupdatesql') !!}" accept-charset="UTF-8">
<label for="Nom">Nom : </label><input name="tiersNom" type="text" id="tiersNom" maxlength="50" size="50" value="{{ $letiers[0]->tiers_nom }}"><br>
<label for="Prenom">Prénom : </label><input name="tiersPrenom" type="text" id="tiersPrenom" maxlength="50" size="50" value="{{ $letiers[0]->tiers_prenom }}"><br>
<label for="Production">Société de production : </label><input type="radio" name="production" value="0" {{ ($letiers[0]->tiers_societeproduction==0 ) ? "checked" : '' }}> Non <input type="radio" name="production" value="1" {{ ($letiers[0]->tiers_societeproduction==1 ) ? "checked" : '' }}> Oui<br>
#if ( $boiteprod->count()==0 )
<label for="Production">Pas de boite de production dans la base.</label>
#else
<label for="Production">Manager par la boite de production : </label>
<select name="production" id="production">
<option value="">--- choisir une boite de production ---</option>
#foreach ($boiteprod as $bprod)
<option value="{{ $bprod->tiers_id }}" {{ ($bprod->tiers_id==$letiers[0]->tiers_societeproduction ) ? "selected=selected" : '' }}>{{ $bprod->tiers_nom }} {{ $bprod->ville_name }} ({{ $bprod->zip_code }})</option>
#endforeach
</select>
#endif
<br>
<label for="ville"> Ville : </label>
<select name="ville" id="ville">
<option value="">--- choisir une ville ---</option>
#foreach ($villes as $ville)
<option value="{{ $ville->ville_id }}" {{ ($ville->ville_id==$letiers[0]->tiers_ville ) ? "selected=selected" : '' }}>{{ $ville->ville_name }} ({{ $ville->zip_code }}), {{ $ville->namedept }}-{{ $ville->nom_fr_fr }}</option>
#endforeach
</select><br>
<label for="tiersIPTC1">Thème : </label>
<select name="tiersiptc1" id="tiersiptc1">
<option value="0">Choisissez un thème principal</option>
#foreach ($iptc1s as $iptc1)
#if( !empty($letiers[0]->tiers_id) )
<option value="{{ $iptc1->IPTC1_Id }}" {{ ($iptc1->IPTC1_Id==$letiers[0]->tiers_iptc1) ? "selected=selected" : '' }}>{{ $iptc1->IPTC1_NomFR }}</option>
#else
<option value="{{ $iptc1->IPTC1_Id }}">{{ $iptc1->IPTC1_NomFR }}</option>
#endif
#endforeach
</select><label for="tiersIPTC2">, </label>
<select name="tiersiptc2" id="tiersiptc2">
<option value="0">---</option>
#foreach ($iptc2s as $iptc2)
#if( !empty($letiers[0]->tiers_id) )
<option value="{{ $iptc2->IPTC2_Id }}" CLASS="{{ $iptc2->IPTC2_IPTC1 }}" {{ ($iptc2->IPTC2_Id==$letiers[0]->tiers_iptc2 ) ? "selected=selected" : '' }}>{{ $iptc2->IPTC2_NomFR }} ({{ $iptc2->IPTC2_Numero }})</option>
#else
<option value="{{ $iptc2->IPTC2_Id }}" CLASS="{{ $iptc2->IPTC2_IPTC1 }}">{{ $iptc2->IPTC2_NomFR }} ({{ $iptc2->IPTC2_Numero }})</option>
#endif
#endforeach
</select><label for="tiersIPTC3">, </label>
<select name="tiersiptc3" id="tiersiptc3">
<option value="">---</option>
#foreach ($iptc3s as $iptc3)
#if( !empty($letiers[0]->tiers_id) )
<option value="{{ $iptc3->IPTC3_Id }}" CLASS="{{ $iptc3->IPTC3_IPTC2 }}"{{ ($iptc3->IPTC3_Id==$letiers[0]->tiers_iptc3 ) ? "selected=selected" : '' }}>{{ $iptc3->IPTC3_NomFR }}</option>
#else
<option value="{{ $iptc3->IPTC3_Id }}" CLASS="{{ $iptc3->IPTC3_IPTC2 }}">{{ $iptc3->IPTC3_NomFR }}</option>
#endif
#endforeach
</select>
<br>
{!! csrf_field() !!}
<input name="tiersModif" type="hidden" id="tiersModif" value="{{ $letiers[0]->tiers_id }}">
<input type="submit" value="Modifier">
Annuler
</form>
#endif
#endsection
#section('scripts')
<script src="{{ asset('js/app.js') }}"></script>
<script src="//code.jquery.com/jquery-1.11.3.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-chained/1.0.1/jquery.chained.js"></script>
<script>
$(function() {
$('#tiersiptc2').chained('#tiersiptc1');
$('#tiersiptc3').chained('#tiersiptc2');
});
</script>
#endsection
I have 2 fields sexe and adresse, my variable sexe is a dropdownlist.
I select an item for example tha value homme. Then, the value of the adresse is Rue du Lac 15.
In my example, the validation is wrong...
Why, the item of my variable sexe is empty? Where is my value?
I don't understand where is my problem?
<fieldset class="form-group {{ $errors->has('sexe') ? 'has-error' : '' }}">
<label for="company-content">Sexe</label>
<select name="sexe" id="sexe" class="form-control" required="required" value="{{ old('sexe')}}"/>
<option value="">Choix sexe</option>
<option>Femme</option>
<option>Homme</option>
{!! $errors->first('sexe', '<span class="help-block">:message</span>') !!}
</select>
</fieldset>
<fieldset class="form-group {{ $errors->has('adresse') ? 'has-error' : '' }}">
<label for="form-group-input-1">Adresse</label>
<input type="text" name="adresse" id="adresse" class="form-control" required="required" value="{{ old('adresse')}}"/>
{!! $errors->first('adresse', '<span class="help-block">:message</span>') !!}
</fieldset>
Your sexe options don't have any value. Edit your code:
<option value="femme">Femme</option>
<option value="homme">Homme</option>
How to use isset if i use select option?
Please help.
This is how i use to get my data for normal insert.
<div class="form-group">
<label>Zone Name</label>
<input type="text" name="name" class="form-control" value="{{ old('name',isset($zone) ? $zone->name : '') }}" placeholder="Name">
</div>
But i don't know how to use isset in select option.
<div class="form-group">
<label>Select Country</label>
<select class="form-control" name="country_id">
<option value="" selected>Please Select</option>
#if ($country->count())
#foreach($country as $c)
<option value="{{ $c->country_id }}" {{ $selectCountry == $c->country_id ? : '' }}>{{ $c->name }}</option>
#endforeach
#endif
</select>
</div>
This is my Controller
public function edit(Request $request, $id){
$zone = Zone::find($id);
$country = Country::all();
$selectCountry= Country::first()->country_id;
if(!$zone){
return redirect('/');
}
return view('zone.edit',['zone' => $zone, 'country'=>$country, 'selectCountry'=>$selectCountry]);
}
my expected result is when i press on edit button, it will show the previous selected result.
You can write
<select class="form-control" name="country_id">
<option value="" {{ !isset($selectCountry) ? 'selected' : '' }}>Please Select</option>
#if ($country->count())
#foreach($country as $c)
<option value="{{ $c->country_id }}" {{ (isset($selectCountry) && $selectCountry == $c->country_id) ? 'selected' : '' }}>{{ $c->name }}</option>
#endforeach
#endif
</select>