21 $this->label = esc_html__(
'Survey',
'gk-gravityview' );
23 add_action(
'gravityview/template/field/survey/rating/before', array( __CLASS__,
'output_frontend_css' ) );
25 parent::__construct();
43 if ( !
$field->gsurveyLikertEnableScoring ) {
47 if ( ! is_array(
$field->choices ) ) {
51 foreach (
$field->choices as $choice ) {
53 return $choice[
'score'];
54 }
else if ( ! is_array(
$value ) && RGFormsModel::choice_value_match(
$field, $choice,
$value ) ) {
55 return $choice[
'score'];
64 unset( $field_options[
'search_filter'] );
66 if (
'edit' === $context ) {
67 return $field_options;
72 $add_options = array();
74 $glue = apply_filters(
'gravityview/template/field/survey/glue',
'; ' );
75 $multiple_rows_suffix = sprintf( _x(
' (separated by %s)',
'text added to a label if multiple rows are enabled for the field)',
'gk-gravityview' ), esc_html( trim(
$glue ) ) );
77 if (
'likert' ===
$field->field->inputType ) {
79 $show_suffix =
$input_id || empty(
$field->field->gsurveyLikertEnableMultipleRows );
81 $likert_display_options = array(
82 'default' => __(
'A table (default Gravity Forms formatting)',
'gk-gravityview' ),
83 'text' => __(
'Text value of the selected choice',
'gk-gravityview' ) . ( $show_suffix ?
'' : $multiple_rows_suffix ),
86 if(
$field->field->gsurveyLikertEnableScoring ) {
87 $likert_display_options[
'score'] = __(
'Score value of the selected choice',
'gk-gravityview' ) . ( $show_suffix ?
'' : $multiple_rows_suffix );
91 $add_options[
'score'] = array(
97 $add_options[
'choice_display'] = array(
99 'label' => __(
'What should be displayed:',
'gk-gravityview' ),
100 'options' => $likert_display_options,
102 'group' =>
'display',
104 'value' =>
'default',
105 'merge_tags' =>
false,
110 $field_options[
'choice_display'] = array(
112 'class' =>
'vertical',
113 'label' => __(
'What should be displayed:',
'gk-gravityview' ),
117 'tick' => __(
'A check mark, if the input is checked',
'gk-gravityview' ),
118 'text' => __(
'Text value of the selected choice',
'gk-gravityview' ),
120 'group' =>
'display',
125 if (
'rating' ===
$field->field->inputType ) {
126 $field_options[
'choice_display'] = array(
128 'class' =>
'vertical',
129 'label' => __(
'What should be displayed:',
'gk-gravityview' ),
130 'value' =>
'default',
133 'default' => __(
'Text value of the selected choice',
'gk-gravityview' ),
134 'stars' => __(
'Stars (default Gravity Forms formatting)',
'gk-gravityview' ),
136 'group' =>
'display',
141 return $add_options + $field_options;
161 $star0 =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1107 844.2 51.6 51.6"><style type="text/css">.st0{fill:#EEEEEE;}.st1{fill:#CCCCCC;}</style><circle class="st0" cx="-1081.2" cy="870" r="17.9"/><path class="st1" d="M-1081.2 895.8c-14.2 0-25.8-11.5-25.8-25.8s11.6-25.8 25.8-25.8c14.2 0 25.8 11.6 25.8 25.8S-1066.9 895.8-1081.2 895.8zM-1081.2 849.2c-11.5 0-20.8 9.3-20.8 20.8s9.3 20.8 20.8 20.8 20.8-9.3 20.8-20.8S-1069.7 849.2-1081.2 849.2z"/><path class="st1" d="M-1076.4 871.8l4.8-4.6 -6.6-1 -3-6 -3 6 -6.6 1 4.8 4.6 -1.1 6.6 5.9-3.1 5.9 3.1L-1076.4 871.8zM-1068.2 866.2c0 0.2-0.1 0.5-0.4 0.8l-5.7 5.5 1.3 7.8c0 0.1 0 0.2 0 0.3 0 0.5-0.2 0.8-0.6 0.8 -0.2 0-0.4-0.1-0.6-0.2l-7-3.7 -7 3.7c-0.2 0.1-0.4 0.2-0.6 0.2 -0.2 0-0.4-0.1-0.5-0.2s-0.2-0.3-0.2-0.6c0-0.1 0-0.2 0-0.3l1.3-7.8 -5.7-5.5c-0.3-0.3-0.4-0.5-0.4-0.8 0-0.4 0.3-0.6 0.9-0.7l7.8-1.1 3.5-7.1c0.2-0.4 0.5-0.6 0.8-0.6 0.3 0 0.6 0.2 0.8 0.6l3.5 7.1 7.8 1.1C-1068.5 865.6-1068.2 865.8-1068.2 866.2L-1068.2 866.2z"/></svg>';
162 $star1 =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1107 844.2 51.6 51.6"><style type="text/css">.st0{fill:#EEEEEE;}.st1{fill:#CCCCCC;}.st2{fill:#FF9800;}</style><circle class="st0" cx="-1081.2" cy="870" r="17.9"/><path class="st1" d="M-1081.2 895.8c-14.2 0-25.8-11.5-25.8-25.8s11.6-25.8 25.8-25.8c14.2 0 25.8 11.6 25.8 25.8S-1066.9 895.8-1081.2 895.8zM-1081.2 849.2c-11.5 0-20.8 9.3-20.8 20.8s9.3 20.8 20.8 20.8 20.8-9.3 20.8-20.8S-1069.7 849.2-1081.2 849.2z"/><path class="st2" d="M-1068.2 866.3c0 0.2-0.1 0.5-0.4 0.8l-5.7 5.5 1.3 7.8c0 0.1 0 0.2 0 0.3 0 0.2-0.1 0.4-0.2 0.6 -0.1 0.2-0.3 0.2-0.5 0.2 -0.2 0-0.4-0.1-0.6-0.2l-7-3.7 -7 3.7c-0.2 0.1-0.4 0.2-0.6 0.2 -0.2 0-0.4-0.1-0.5-0.2 -0.1-0.2-0.2-0.3-0.2-0.6 0-0.1 0-0.2 0-0.3l1.3-7.8 -5.7-5.5c-0.3-0.3-0.4-0.5-0.4-0.8 0-0.4 0.3-0.6 0.9-0.7l7.8-1.1 3.5-7.1c0.2-0.4 0.5-0.6 0.8-0.6 0.3 0 0.6 0.2 0.8 0.6l3.5 7.1 7.8 1.1C-1068.5 865.7-1068.2 865.9-1068.2 866.3L-1068.2 866.3z"/></svg>';
166 .gv-field-survey-star-filled,
167 .gv-field-survey-star-empty {
170 display:
inline-block;
171 background: transparent url(
'data:image/svg+xml;base64,<?php echo base64_encode( $star0 ); ?>') left
top no-repeat;
172 background-size: contain;
174 .gv-field-survey-star-filled {
175 background-image: url(
'data:image/svg+xml;base64,<?php echo base64_encode( $star1 ); ?>');
177 .gv-field-survey-screen-reader-text {
180 clip-path: inset(50%);
189 .gv-field-survey-screen-reader-text.focusable {
190 .gv-field-survey-screen-reader-text:active,
191 .gv-field-survey-screen-reader-text:focus {
199 white-space: inherit;
Modify field settings by extending this class.
gravityview_get_input_id_from_id( $field_id='')
Very commonly needed: get the # of the input based on a full field ID.
static by_id( $form, $field_id)
Get a by and Field ID.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
static get_choice_score( $field, $value, $input_id=0)
Returns the score for a choice at $value.
if(empty( $created_by)) $form_id
new GravityView_Field_Survey
static output_frontend_css()
Output CSS for star ratings.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed