Results 1 to 1 of 1

Thread: Changing checkbox images

  1. #1
    Thread Starter
    chimera's Avatar
    Join Date
    Jun 2012
    Location
    United Kingdom
    Posts
    18
    Thanks
    11
    Thanked 2 Times in 2 Posts

    Changing checkbox images

    I have successfully changed the checkbox images in the main search form via css, and would like to do the same in the step-functions.php (lines157-182) file.

    Code:
    case 'checkbox':
    
    							$post_meta_val = ( $post ) ? get_post_meta($post->ID, $result->field_name, false) : array();
    							$options = explode( ',', $result->field_values );
    							$options = array_map( 'trim', $options );
    							$optionCursor = 1;
    
    							$html_checkbox = '';
    							$html_options = '';
    							
    							foreach ( $options as $option ) {
    								$field_class = ( $result->field_req ) ? 'checkboxlist required' : 'checkboxlist';
    								$args = array( 'value' => $option, 'type' => 'checkbox', 'class' => $field_class, 'name' => $result->field_name . '[]', 'id' => $result->field_name . '_' . $optionCursor++ );
    								if ( in_array($option, $post_meta_val) )
    									$args['checked'] = 'checked';
    								$args = apply_filters( 'cp_formbuilder_' . $result->field_name, $args, $result, $post );
    $html_checkbox = html( 'input', $args ) . '  ' . $option;
    								$html_options .= html( 'li', array(), $html_checkbox );
    							}
    
    							echo html( 'ol', array( 'class' => 'checkboxes' ), $html_options );
    							echo html( 'div', array( 'class' => 'clr' ) );
    
    							break;

    In order to complete this task, I need to insert a label tag with an identical 'for=' ' value to the option ID.

    Code:
    case 'checkbox':
    
    							$post_meta_val = ( $post ) ? get_post_meta($post->ID, $result->field_name, false) : array();
    							$options = explode( ',', $result->field_values );
    							$options = array_map( 'trim', $options );
    							$optionCursor = 1;
    
    							$html_checkbox = '';
    							$html_options = '';
    							
    							foreach ( $options as $option ) {
    								$field_class = ( $result->field_req ) ? 'checkboxlist required' : 'checkboxlist';
    								$args = array( 'value' => $option, 'type' => 'checkbox', 'class' => $field_class, 'name' => $result->field_name . '[]', 'id' => $result->field_name . '_' . $optionCursor++ );
    								if ( in_array($option, $post_meta_val) )
    									$args['checked'] = 'checked';
    								$args = apply_filters( 'cp_formbuilder_' . $result->field_name, $args, $result, $post );
    								//#add label within li
    								$html_checkbox = html( 'input', $args ) . '   
    								<label for=' . $result->field_name . '_' . $optionCursor . '>' . $option . '</label>';
    								$html_options .= html( 'li', array(), $html_checkbox );
    							}
    
    							echo html( 'ol', array( 'class' => 'checkboxes' ), $html_options );
    							echo html( 'div', array( 'class' => 'clr' ) );
    
    							break;
    I can add the label as above, but my issue is that $optionCursor creating the ID value, and this increments by 1, producing the wrong ID value ie. if ID = 1, the label $optionCursor = 2. Adding a decrement (--) before or after $optionCursor doesn't work, and I'm not sure how to dynamically duplicate/clone the previous ID value. Is there a simple way around this? Any pointers would be appreciated :)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Changing featured images seems to mess things up.
    By shunarjuna in forum Report Vantage Bugs (Legacy)
    Replies: 1
    Last Post: September 20th, 2012, 09:31 PM
  2. Changing the images for the Job Categories
    By thebaht in forum JobRoller General Discussion
    Replies: 2
    Last Post: February 6th, 2012, 06:47 AM
  3. Checkbox on insert new ads
    By ran55 in forum ClassiPress General Discussion
    Replies: 3
    Last Post: February 3rd, 2012, 02:25 PM
  4. [MOD NEEDED] changing slider arrow images
    By alimacca in forum ClassiPress General Discussion
    Replies: 2
    Last Post: August 9th, 2011, 05:28 AM