stars(), stars_select() form()

A rating: stars() shows the value as stars, stars_select() lets the visitor pick one with radio stars.

form()->stars($name = '', $desc = '', $extra = [], $replace = [])
form()->stars_select($name = '', $desc = '', $extra = [], $replace = [])

Options

OptionMeaning
stars, maxNumber of stars (5); value of a full row (5).
color_ok, color_ko, class, class_ok, class_koColours and classes of lit and dim stars (stars()).
value, selectedstars_select() with yf_form2_stars::$SELECT_FIX: the start value (else $replace[name], then the filter).

Example

Code

return form(['rating' => 4, 'your_rating' => 3])
    ->stars('rating')
    ->stars_select('your_rating', 'Your rating');

Notes

  • stars_select() keeps its value only with yf_form2_stars::$SELECT_FIX on (Settings / Widget fixes; the 4.0 default): it starts at the stored rating, marks the chosen stars with the class rating_selected and posts the choice. Off, as before: the field starts at 0 on every render (an edit form saves 0) and a click marks nothing. Style the chosen stars with .rating span.star.rating_selected:before.

See also: table/stars