My initial problem is that the radio button html structure that views produces is
<ul>
<li><label><input></label></li>
<li><label><input></label></li>
</ul>
To use some sibling combinators I need the structure to be different. The cred generic fields are better as they output:
<ul>
<li><input><label></label></li>
<li><input><label></label></li>
</ul>
What I need is a structure that's just:
<fieldset>
<input><label></label>
<input><label></label>
</fieldset>
So I've created a shortcode to produce the required output:
// Star Rating Shortcode
add_shortcode("rating_stars_shortcode", "rating_stars_function");
function rating_stars_function ( $atts = '' ) {
$value = shortcode_atts( array(
'field' => ''
), $atts );
$output = "";
$output .= '<div class="star-rating">';
$output .= ' <fieldset>';
$output .= ' <input type="radio" id="form-'.$value['field'].'5" name="'.$value['field'].'" value="5">';
$output .= ' <label for="form-'.$value['field'].'5">5</label>';
$output .= ' <input type="radio" id="form-'.$value['field'].'4" name="'.$value['field'].'" value="4">';
$output .= ' <label for="form-'.$value['field'].'4">4</label>';
$output .= ' <input type="radio" id="form-'.$value['field'].'3" name="'.$value['field'].'" value="3">';
$output .= ' <label for="form-'.$value['field'].'3">3</label>';
$output .= ' <input type="radio" id="form-'.$value['field'].'2" name="'.$value['field'].'" value="2">';
$output .= ' <label for="form-'.$value['field'].'2">2</label>';
$output .= ' <input type="radio" id="form-'.$value['field'].'1" name="'.$value['field'].'" value="1">';
$output .= ' <label for="form-'.$value['field'].'1">1</label>';
$output .= ' </fieldset>';
$output .= '</div>';
return $output;
}
This works just fine if I call the shortcode from a page, a view or a content template, but when I call it from inside a Post Form the "for" fields of the labels are given the wrong value. So the output I expect is:
<div class="star-rating">
<fieldset>
<input type="radio" id="form-wpcf-review-experience5" name="wpcf-review-experience" value="5">
<label for="form-wpcf-review-experience5">5</label>
<input type="radio" id="form-wpcf-review-experience4" name="wpcf-review-experience" value="4">
<label for="form-wpcf-review-experience4">4</label>
<input type="radio" id="form-wpcf-review-experience3" name="wpcf-review-experience" value="3">
<label for="form-wpcf-review-experience3">3</label>
<input type="radio" id="form-wpcf-review-experience2" name="wpcf-review-experience" value="2">
<label for="form-wpcf-review-experience2">2</label>
<input type="radio" id="form-wpcf-review-experience1" name="wpcf-review-experience" value="1">
<label for="form-wpcf-review-experience1">1</label>
</fieldset>
</div>
The output I get is:
<div class="star-rating">
<fieldset>
<input type="radio" id="form-wpcf-review-experience5" name="wpcf-review-experience" value="5">
<label for="form-wpcf-review-experience5">5</label>
<input type="radio" id="form-wpcf-review-experience4" name="wpcf-review-experience" value="4">
<label for="form-wpcf-review-experience5">4</label>
<input type="radio" id="form-wpcf-review-experience3" name="wpcf-review-experience" value="3">
<label for="form-wpcf-review-experience5">3</label>
<input type="radio" id="form-wpcf-review-experience2" name="wpcf-review-experience" value="2">
<label for="form-wpcf-review-experience5">2</label>
<input type="radio" id="form-wpcf-review-experience1" name="wpcf-review-experience" value="1">
<label for="form-wpcf-review-experience5">1</label>
</fieldset>
</div>
i.e. all of the labels have the same "for" value which is pulled from the first label. This means that clicking in all numbers cause 5 to be selected.
Even if I hardcode it into the form it does the same. It only happens on forms - is this a bug? Anyway, I'm hoping you can help me to solve it this. Ideally I'd like to be able to select the format of the form output so I can choose how my radiobutton is coded, but if not then stopping it from changing my "for" values would be good.
Thanks
Tim