0

I have downloaded a starter for form controls for mysql user registration page. Everything seems to work fine with bootstrap 3 (not 4) in terms of styling when error. I took a closer look at the code and am scratching my head about something, below is a snippet of the form:

<div class="form-group <?php echo (!empty($city_err)) ? 'has-error' : ''; ?>">
 <label>City</label>
 <input type="text" name="city" class="form-control" value="<?php echo $city; ?>">
 <span class="help-block"><?php echo $city_err; ?></span>
</div>

If you look at the class, the error message is in the quotation marks (for class). I'm assuming this is a typo, because I don't know why that would be a class, but then what's going on with the error message? It has to be assigned an HTML tag, but which one?

grunt
  • 79
  • 8
  • 1
    It adds the class `has-error` or does nothing (well echos an empty string). See [`ternary`](https://stackoverflow.com/questions/17981723/how-to-write-a-php-ternary-operator). – ficuscr Oct 16 '18 at 20:33
  • 1
    not a typo its Ternary operator –  Oct 16 '18 at 20:35
  • 1
    *"the error message is in the quotation marks (for class)"* - No it isn't. The class `has-error` is conditionally emitted depending on whether or not there is an error message. The error *message* is in the `` element. – David Oct 16 '18 at 20:35
  • 1
    Maybe it's the `ternary` or Shorthand IF/THEN that is confusing you? Basically `condition ? true : false` is the same as `if(condition) true else false` – ArtisticPhoenix Oct 16 '18 at 20:36
  • Thanks all. That clears that up – grunt Oct 16 '18 at 20:36

0 Answers0