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

Saturday, January 1, 2022

[FIXED] Switching toggle-wrap based on database value

 January 01, 2022     codeigniter, php, twitter-bootstrap-3     No comments   

Issue

Currently I have a toggle-wrap switch in my update page. As of now in my database, the value for this can be Null, No and Yes. So when the user enters the page, I want this switch to be off if the database value is in Null or no and switched on if the database value is Yes in the database. I've tried the following to enable the toggle but it does not toggle on when the data value in my database is Yes.

View Class:

<label class="control-labels mr-4">Lead Gen?</label>
                    <div class="toggle-wrap tg-list-item">
                        <input class="tgl tgl-light" id="leadgen" name="leadgen" type="checkbox" 
                        <?php echo ($listing[0]['leadgen'] == 'Yes' ? 'enabled':'disabled'); ?> />
                        <label class="tgl-btn" for="leadgen"></label>
                    </div>

Doing a var_dump on $listing[0]['leadgen'] gave me string(3) "Yes" But the switch still doesn't turn on


Solution

Instead of using 'enable' and 'disable' have a look at checked. Your code would become:

<label class="control-labels mr-4">Lead Gen?</label>
                    <div class="toggle-wrap tg-list-item">
                        <input class="tgl tgl-light" id="leadgen" name="leadgen" type="checkbox" 
                        <?php echo ($listing[0]['leadgen'] == 'Yes' ? 'checked' : ''); ?> />
                        <label class="tgl-btn" for="leadgen"></label>
                    </div>


Answered By - KIKO Software
  • 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