slug = 'OneChoice'; $this->title = esc_attr__( 'One Choice', 'questions-locale' ); $this->description = esc_attr__( 'Add a question which can be answered by selecting one of the given answers.', 'questions-locale' ); $this->icon_url = QUESTIONS_URLPATH . '/assets/images/icon-onechoice.png'; $this->has_answers = TRUE; $this->answer_is_multiple = FALSE; $this->is_analyzable = TRUE; $this->create_answer_syntax = '
'; $this->create_answer_params = array( 'name', 'answer' ); parent::__construct( $id ); } public function input_html() { $html = ''; foreach ( $this->answers AS $answer ): $checked = ''; if ( $this->response == $answer[ 'text' ] ) { $checked = ' checked="checked"'; } $html .= '' . $answer[ 'text' ] . '
'; endforeach; return $html; } public function settings_fields() { $this->settings_fields = array( 'description' => array( 'title' => esc_attr__( 'Description', 'questions-locale' ), 'type' => 'textarea', 'description' => esc_attr__( 'The description will be shown after the question.', 'questions-locale' ), 'default' => '' ) ); } public function validate( $input ) { $error = FALSE; if ( empty( $input ) ): $this->validate_errors[ ] = sprintf( esc_attr__( 'Please select a value.', 'questions-locale' ) ); $error = TRUE; endif; if ( $error ): return FALSE; endif; return TRUE; } } qu_register_survey_element( 'Questions_FormElement_OneChoice' );