* @subpackage Questions * @author Sven Wagener * @copyright 2015, awesome.ug * @link http://awesome.ug * @license http://www.opensource.org/licenses/gpl-2.0.php GPL License */ // No direct access is allowed if (!defined('ABSPATH')) { exit; } class Questions_FormElement_Splitter extends Questions_FormElement { public function __construct($id = NULL) { $this->slug = 'Splitter'; $this->title = esc_attr__('Split Form', 'questions-locale'); $this->description = esc_attr__('Splits a form into several steps', 'questions-locale'); $this->icon_url = QUESTIONS_URLPATH . '/assets/images/icon-split-form.png'; $this->is_question = FALSE; $this->splits_form = TRUE; parent::__construct($id); } public function settings_fields() { } public function get_html() { } } qu_register_survey_element('Questions_FormElement_Splitter');
$error = FALSE; if (!empty($min_length)) { if (strlen($input) < $min_length) { $this->validate_errors[] = esc_attr__('The input ist too short.', 'questions-locale') . ' ' . sprintf(esc_attr__('It have to be at minimum %d and maximum %d chars.', 'questions-locale'), $min_length, $max_length); $error = TRUE; } } if (!empty($max_length)) { if (strlen($input) > $max_length) { $this->validate_errors[] = esc_attr__('The input is too long.', 'questions-locale') . ' ' . sprintf(esc_attr__('It have to be at minimum %d and maximum %d chars.', 'questions-locale'), $min_length, $max_length); $error = TRUE; } } if ($error) { return FALSE; } return TRUE; } public function after_question() { $html = ''; if (!empty($this->settings['description'])) { $html = '<p class="questions-element-description">'; $html .= $this->settings['description']; $html .= '</p>'; } return $html; } } qu_register_survey_element('Questions_FormElement_Textarea');
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' => ''), 'min_answers' => array('title' => esc_attr__('Minimum Answers', 'questions-locale'), 'type' => 'text', 'description' => esc_attr__('The minimum number of answers which have to be choosed.', 'questions-locale'), 'default' => '1'), 'max_answers' => array('title' => esc_attr__('Maximum Answers', 'questions-locale'), 'type' => 'text', 'description' => esc_attr__('The maximum number of answers which can be choosed.', 'questions-locale'), 'default' => '3')); } public function validate($input) { $min_answers = $this->settings['min_answers']; $max_answers = $this->settings['max_answers']; $error = FALSE; if (!empty($min_answers)) { if (!is_array($input) || count($input) < $min_answers) { $this->validate_errors[] = esc_attr__('Too less choices.', 'questions-locale') . ' ' . sprintf(esc_attr__('You have to choose between %d and %d answers.', 'questions-locale'), $min_answers, $max_answers); $error = TRUE; } } if (!empty($max_answers)) { if (is_array($input) && count($input) > $max_answers) { $this->validate_errors[] = esc_attr__('Too many choices.', 'questions-locale') . ' ' . sprintf(esc_attr__('You have to choose between %d and %d answers.', 'questions-locale'), $min_answers, $max_answers); $error = TRUE; } } if ($error) { return FALSE; } return TRUE; } } qu_register_survey_element('Questions_FormElement_MultipleChoice');
* @subpackage Questions * @author Sven Wagener * @copyright 2015, awesome.ug * @link http://awesome.ug * @license http://www.opensource.org/licenses/gpl-2.0.php GPL License */ // No direct access is allowed if (!defined('ABSPATH')) { exit; } class Questions_FormElement_Description extends Questions_FormElement { public function __construct($id = NULL) { $this->slug = 'Description'; $this->title = esc_attr__('Description', 'questions-locale'); $this->description = esc_attr__('Adds a text to the form.', 'questions-locale'); $this->icon_url = QUESTIONS_URLPATH . '/assets/images/icon-text.png'; $this->is_question = FALSE; parent::__construct($id); } public function input_html() { } public function settings_fields() { $this->settings_fields = array('description' => array('title' => esc_attr__('Text to show', 'questions-locale'), 'type' => 'textarea', 'description' => esc_attr__('The text which will be shown in the form.', 'questions-locale'), 'default' => '')); } } qu_register_survey_element('Questions_FormElement_Description');
// No direct access is allowed if (!defined('ABSPATH')) { exit; } class Questions_FormElement_Separator extends Questions_FormElement { public function __construct($id = NULL) { $this->slug = 'Separator'; $this->title = esc_attr__('Separator', 'questions-locale'); $this->description = esc_attr__('Adds a optical separator (<hr>) between questions.', 'questions-locale'); $this->icon_url = QUESTIONS_URLPATH . '/assets/images/icon-separator.png'; $this->is_question = FALSE; parent::__construct($id); } public function input_html() { $html = '<div class="survey-element survey-element-' . $this->id . '">'; if (!empty($this->settings['header'])) { $html .= '<h3>' . $this->settings['header'] . '</h3>'; } $html .= '<hr /></div>'; return $html; } public function settings_fields() { $this->settings_fields = array('header' => array('title' => esc_attr__('Headline', 'questions-locale'), 'type' => 'textarea', 'description' => esc_attr__('Text which will be shown above the separator', 'questions-locale'), 'default' => '')); } } qu_register_survey_element('Questions_FormElement_Separator');
$html = '<select name="' . $this->get_input_name() . '">'; $html .= '<option value="please-select"> - ' . esc_attr__('Please select', 'questions-locale') . ' -</option>'; foreach ($this->answers as $answer) { $checked = ''; if ($this->response == $answer['text']) { $checked = ' selected="selected"'; } $html .= '<option value="' . $answer['text'] . '" ' . $checked . '/> ' . $answer['text'] . '</option>'; } $html .= '</select>'; 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 ('please-select' == $input) { $this->validate_errors[] = sprintf(esc_attr__('Please select a value.', 'questions-locale')); $error = TRUE; } if ($error) { return FALSE; } return TRUE; } } qu_register_survey_element('Questions_FormElement_Dropdown');