Code for description of adding label tags to radio field type items
<?php
/**
* Create form label.
*
* @since 3.1.7
*
* @param array $args {
* @type string $meta_key
* @type string $label_text
* @type string $type
* @type string $class (optional)
* @type string $required (optional)
* @type string $req_mark (optional)
* }
* @return string $label
*/
function create_form_label( $args ) {
global $wpmem;
$meta_key = $args['meta_key'];
$label = $args['label'];
$type = $args['type'];
$class = ( isset( $args['class'] ) ) ? $args['class'] : false;
$required = ( isset( $args['required'] ) ) ? $args['required'] : false;
$req_mark = ( isset( $args['req_mark'] ) ) ? $args['req_mark'] : false;
//$req_mark = ( ! $req_mark ) ? $wpmem->get_text( 'register_req_mark' ) : '*';
if ( ! $class ) {
$class = ( $type == 'password' || $type == 'email' || $type == 'url' ) ? 'text' : $type;
}
$label = '<label for="' . esc_attr( $meta_key ) . '" class="' . $this->sanitize_class( $class ) . '">' . __( $label, 'wp-members' );
$label = ( $required ) ? $label . $req_mark : $label;
$label = $label . '</label>';
return $label;
}
<?php
/**
* Create form label.
*
* @since 3.1.7
* @since 3.2.4 Added $id
*
* @param array $args {
* @type string $meta_key
* @type string $label
* @type string $type
* @type string $id (optional)
* @type string $class (optional)
* @type string $required (optional)
* @type string $req_mark (optional)
* }
* @return string $label
*/
function create_form_label( $args ) {
global $wpmem;
$meta_key = $args['meta_key'];
$label = $args['label'];
$type = $args['type'];
$class = ( isset( $args['class'] ) ) ? $args['class'] : false;
$id = ( isset( $args['id'] ) ) ? $args['id'] : false;
$required = ( isset( $args['required'] ) ) ? $args['required'] : false;
$req_mark = ( isset( $args['req_mark'] ) ) ? $args['req_mark'] : false;
//$req_mark = ( ! $req_mark ) ? $wpmem->get_text( 'register_req_mark' ) : '*';
if ( ! $class ) {
$class = ( $type == 'password' || $type == 'email' || $type == 'url' ) ? 'text' : $type;
}
$id = ( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
$label = '<label for="' . esc_attr( $meta_key ) . '"' . $id . ' class="' . $this->sanitize_class( $class ) . '">' . __( $label, 'wp-members' );
$label = ( $required ) ? $label . $req_mark : $label;
$label = $label . '</label>';
return $label;
}
<?php
case "radio":
$class = ( 'textbox' == $class ) ? "radio" : $this->sanitize_class( $class );
$str = '';
$num = 1;
foreach ( $value as $option ) {
$pieces = explode( '|', $option );
$id = $this->sanitize_class( $id . '_' . $num );
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
$str = $str . "<input type=\"radio\" name=\"$name\" id=\"$id\" value=\"" . esc_attr( $pieces[1] ) . '"' . checked( $pieces[1], $compare, false ) . ( ( $required ) ? " required " : " " ) . "> " . esc_html( __( $pieces[0], 'wp-members' ) ) . "<br />\n";
} else {
$str = $str . '<span class="div_radio_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
}
$num++;
}
break;
<?php
case "radio":
$class = ( 'textbox' == $class ) ? "radio" : $this->sanitize_class( $class );
$str = '';
$num = 1;
foreach ( $value as $option ) {
$pieces = explode( '|', $option );
$id_num = $id . '_' . $num;
if ( isset( $pieces[1] ) && '' != $pieces[1] ) {
$label = wpmem_form_label( array( 'meta_key'=>esc_attr( $id_num ), 'label'=>esc_html( __( $pieces[0], 'wp-members' ) ), 'type'=>'radio', 'id'=>esc_attr( "label_" . $id_num ) ) );
$str = $str . "<input type=\"radio\" name=\"$name\" id=\"" . esc_attr( $id_num ) . "\" value=\"" . esc_attr( $pieces[1] ) . '"' . checked( $pieces[1], $compare, false ) . ( ( $required ) ? " required " : " " ) . "> $label<br />\n";
$num++;
} else {
$str = $str . '<span class="div_radio_separator">' . esc_html( __( $pieces[0], 'wp-members' ) ) . "</span><br />\n";
}
}
break;
<label for="radio_test" class="radio">Radio Test</label>
<div class="div_radio">
<input type="radio" name="radio_test" id="radio_test_1_2" value="choice_one" > Choice One<br />
<input type="radio" name="radio_test" id="radio_test_1_2_3" value="one_thousand" > 1,000<br />
<input type="radio" name="radio_test" id="radio_test_1_2_3_4" value="1,000-10,000" > 1,000-10,000<br />
<input type="radio" name="radio_test" id="radio_test_1_2_3_4_5" value="last_row" > Last Row<br />
</div>
<label for="radio_test" class="radio">Radio Test</label>
<div class="div_radio">
<input type="radio" name="radio_test" id="radio_test_1" value="choice_one" > <label for="radio_test_1" id="radio_test_1" class="radio">Choice One</label><br />
<input type="radio" name="radio_test" id="radio_test_2" value="one_thousand" > <label for="radio_test_2" id="radio_test_2" class="radio">1,000</label><br />
<input type="radio" name="radio_test" id="radio_test_3" value="1,000-10,000" > <label for="radio_test_3" id="radio_test_3" class="radio">1,000-10,000</label><br />
<input type="radio" name="radio_test" id="radio_test_4" value="last_row" > <label for="radio_test_4" id="radio_test_4" class="radio">Last Row</label><br />
</div>