Support

Account

Home Forums General Issues Checkbox and PHP if…

Solved

Checkbox and PHP if…

  • HI,

    First, a big congratulation for this huge and wonderful plugin for WP ! 🙂
    Thanks to authors!

    Well, after some several time elapsed on one of my research…
    I need some help, I hope you’ll help me on this issue

    I created a simple form with a checkbox control
    with these values:

    "en:english"
    "fr:french"

    and in my PHP Code, I would like to test, but it seems doesn’t work 🙁

    This my code :

    <?php if ((get_field('language') == 'en')) { echo "ENGLISH Flag icon"} else {} ?>
    <?php if ((get_field('language') == 'fr')) { echo "FRENCH Flag icon"} else {} ?>

    Result: Array text or nothing appears 🙁

    The goal is to display or not a flag icon, if I check the option in ACF…

    Thanks alot by advance,

    Regards,

    Nico.

  • @mikosworld,

    Try this:

    $lang = get_field('language');
    	
    if ( 'en' === $lang ) { 
    	echo "ENGLISH Flag icon"; 
    }
    elseif ( 'fr' === $lang ) { 
    	echo "FRENCH Flag icon"; 
    }
    
  • Arf, no result 🙁

  • Hi @mikosworld

    You can use this code to test the value. That way you know what you are working with:

    
    <?php 
    
    $lang = get_field('language');
    
    echo '<pre>';
    	var_dump( $lang );
    echo '</pre>';
    die;
    
    ?>
    
  • ok Elliot, thanks but…
    it gets this :

    array(2) {
      [0]=>
      string(2) "en"
      [1]=>
      string(2) "fr"
    }

    How tests “en” checkbox is checked and test “fr” is checked ?

  • 
    <?php 
    
    if( in_array('en', $lang) )
    {
    
    }
    
    ?>
    
  • Excellent, it works now! thank you Elliot! 😀

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Checkbox and PHP if…’ is closed to new replies.