PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, April 19, 2022

[FIXED] How do I load the gender from the database and make it pre-selected in laravel?

 April 19, 2022     forms, laravel, laravel-blade, php     No comments   

Issue

I'm trying to show the user what type of gender they currently have selected. (It's in dutch, Geslacht = Gender)

Here's the code:

<div class="row">
  <div class="col-sm">
    <div class="form-group text-muted">                                         
      <label for="name">Geslacht:</label>                                         
      <select class="custom-select">                                             
        <option selected value="{{Auth::user()->geslacht}}">Kies een optie</option>
        <option value="1">Mannelijk</option>                                             
        <option value="2">Vrouwelijk</option>                                             
        <option value="3">Zeg ik liever niet</option>                                         
      </select>
    </div>
  </div>

Text is in dutch

If you know how I might fix this please let me know ;)


Solution

 <option value="1" @if(Auth::user()->geslacht == 1) selected @endif>Mannelijk</option>
 <option value="2" @if(Auth::user()->geslacht == 2) selected @endif>Vrouwelijk</option>   
 <option value="3" @if(Auth::user()->geslacht == 3) selected @endif>Zeg ik liever niet</option>   

You can check in the option like this and if matched value then you can select it



Answered By - atikur rahman
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing