0

I have an input box where a user can input a number and then that number will be outputted into an html page. It all works fine except when you enter in the number 0 it doesn't output anything but it needs to say 0. This is a live baseball game scoring widget so I need "Inning 1" to read "0" if no runs were scored. Here is the gist of my code:

$t1Inning1 = ( $instance['t1Inning1'] ) ? $instance['t1Inning1'] : '-';

<div><?php echo $t1Inning1 ?></div>

<div><?php echo $t1Inning1 ?></div>
 <label for="<?php echo $this->get_field_id('t1Inning1'); ?>">
 <input id="<?php echo $this->get_field_id('t1Inning1'); ?>"
 name="<?php echo $this->get_field_name('t1Inning1'); ?>"
 value="<?php echo esc_attr( $instance['t1Inning1'] ); ?>"
 maxlength="2" size="3" />
</label>

You can see the output at http://juniorregionals.com/ in the middle left. The '-' is just the default value which doesn't change when you input 0 in the widget and save it but again I need it to read 0 if you input 0.

If I change it to :

$t1Inning1 = isset( $instance['t1Inning1'] ) ? $instance['t1Inning1'] : '-';

it does output a 0 if thats what you put in but then the res of the inning don't show a default slash. the output is empty. So reiterate I need to be able to enter a 0 and have it output a 0 and if the input is empty I need it to have a dash (-).

Let me know if I need to be more specific.

1 Answer 1

0

If you add an exact comparison to the test it should work:

$t1Inning1 = isset( $instance['t1Inning1'] ) && $instance['t1Inning1'] !== '' ? $instance['t1Inning1'] : '-';
1
  • Thank you, thank you, THANK YOU!! That worked perfectly.
    – agon024
    Commented Jul 29, 2014 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.