WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Dropdown menu in custom text fields

[Resolved] Dropdown menu in custom text fields

  • Is there a way to make the answers in a custom text field a dropdown list (or radio buttons or checkboxes)?
    I’m interested in tabulating and cross referencing answers to a poll by age groups and gender. Rather than trying to sort “M”, “male”, “man”, etc, I’d rather be able to get those responding to the poll to choose either “male” or “female”.
    Possible?
    Thanks!

    http://wordpress.org/plugins/yop-poll/

Viewing 1 replies (of 1 total)
  • Plugin Author YOP

    @yourownprogrammer

    Hi WhiteCoat,

    Edit you poll and add a custom field, labeled “Gender” and mark it as “Required”.

    Then edit yop_poll_model.php and replace

    public function customfield_replace_callback( $m ) {
    $poll_id = $this->poll['id'];
    $poll_options = $this->poll_options;
    $return_string = '';
    $is_voted = $this->is_voted();
    if( ! $is_voted ) {
    $custom_fields = self::get_poll_customfields( $poll_id );
    if( count( $custom_fields ) > 0 ) {
    foreach ($custom_fields as $custom_field) {
    if ( 'yes' == $poll_options['poll_custom_field_html_tags'] )
    $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-'.$custom_field['id'].'">'.stripslashes( $custom_field['custom_field'] ).'</label>', $m[5] );
    else
    $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-'.$custom_field['id'].'">'.esc_html( stripslashes( $custom_field['custom_field'] ).'</label>', $m[5] );
    else
    $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-'.$custom_field['id'].'">'.esc_html( stripslashes( $custom_field['custom_field'] ) ).'</label>', $m[5] );
    $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-TEXT-INPUT%', '<input type="text" value="" name="yop_poll_customfield['.$custom_field['id'].']" id="yop-poll-customfield-'.$custom_field['id'].'" />', $temp_string );
    $return_string .= $temp_string;
    }
    }
    }
    return $return_string;
    }
    
    with 
    
    public function customfield_replace_callback( $m ) {
    $poll_id = $this->poll['id'];
    $poll_options = $this->poll_options;
    $return_string = '';
    $is_voted = $this->is_voted();
    if( ! $is_voted ) {
    $custom_fields = self::get_poll_customfields( $poll_id );
    if( count( $custom_fields ) > 0 ) {
    $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-'.$custom_fields[0]['id'].'">'.$custom_fields[0]['custom_field'].'</label>', $m[5] );
     $select_string = '<select name="yop_poll_customfield['.$custom_fields[0]['id'].']" id="yop-poll-customfield-'.$custom_fields[0]['id'].'">';
    $select_string .= '<option value="">--SELECT--</option>';
    $select_string .= '<option value="Male">Male</option>';
    $select_string .= '<option value="Female">Female</option>';
    $select_string .= '</select>';
    $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-TEXT-INPUT%', $select_string, $temp_string );
    $return_string .= $temp_string;
    }
    }
    return $return_string;
    }

    [Moderator Note: Please post code or markup between backticks or use the code button. Or better still – use a pastebin. Your posted code may now have been permanently damaged by the forum’s parser.]

    However, please note that if you make these changes you will not be able to add other custom text fields on any of your polls.

    Best wishes,

    YOP Team

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Dropdown menu in custom text fields’ is closed to new replies.