name; } /** * Get field type * * @return string */ public function get_type() { return $this->input_type; } /** * Get the fontawesome icon for this field * * @return string */ public function get_icon() { return $this->icon; } /** * Render of the field in the frontend * * @param array $field_settings The field configuration from the db * @param integer $form_id The form id * * @return void */ abstract function render( $field_settings, $form_id ); /** * Get the field option settings for form builder * * @return array */ abstract function get_options_settings(); /** * Get the field props * * Field props are the field properties that saves in the database * * @return array */ abstract function get_field_props(); /** * The JS template for using in the form builder * * @return array */ public function get_js_settings() { $settings = array( 'template' => $this->get_type(), 'title' => $this->get_name(), 'icon' => $this->get_icon(), 'pro_feature' => $this->is_pro(), 'settings' => $this->get_options_settings(), 'field_props' => $this->get_field_props(), 'is_full_width' => $this->is_full_width() ); if ( $validator = $this->get_validator() ) { $settings['validator'] = $validator; } return apply_filters( 'weforms_field_get_js_settings', $settings ); } /** * Custom field validator if exists * * @return boolean|array */ public function get_validator() { return false; } /** * Check if it's a pro feature * * @return boolean */ public function is_pro() { return false; } /** * If this field is full width * * Used in form builder preview (hides the label) * * @return boolean */ public function is_full_width() { return false; } /** * Conditional property for all fields * * @return array */ public function default_conditional_prop() { return array( 'condition_status' => 'no', 'cond_field' => array(), 'cond_operator' => array( '=' ), 'cond_option' => array( __( '- select -', 'weforms' ) ), 'cond_logic' => 'all' ); } /** * Default attributes of a field * * Child classes should use this default setting and extend it by using `get_field_settings()` function * * @return array */ public function default_attributes() { return array( 'template' => $this->get_type(), 'name' => '', 'label' => $this->get_name(), 'required' => 'no', 'id' => 0, 'css' => '', 'placeholder' => '', 'default' => '', 'size' => 40, 'help' => '', 'is_meta' => 'yes', // wpuf uses it to differentiate meta fields with core fields, maybe removed 'is_new' => true, // introduced by @edi, not sure what it does. Have to remove 'wpuf_cond' => $this->default_conditional_prop() ); } /** * Common properties for all kinds of fields * * @param boolean $is_meta * * @return array */ public static function get_default_option_settings( $is_meta = true ) { $common_properties = array( array( 'name' => 'label', 'title' => __( 'Field Label', 'weforms' ), 'type' => 'text', 'section' => 'basic', 'priority' => 10, 'help_text' => __( 'Enter a title of this field', 'weforms' ), ), array( 'name' => 'help', 'title' => __( 'Help text', 'weforms' ), 'type' => 'text', 'section' => 'basic', 'priority' => 20, 'help_text' => __( 'Give the user some information about this field', 'weforms' ), ), array( 'name' => 'required', 'title' => __( 'Required', 'weforms' ), 'type' => 'radio', 'options' => array( 'yes' => __( 'Yes', 'weforms' ), 'no' => __( 'No', 'weforms' ), ), 'section' => 'basic', 'priority' => 21, 'default' => 'no', 'inline' => true, 'help_text' => __( 'Check this option to mark the field required. A form will not submit unless all required fields are provided.', 'weforms' ), ), array( 'name' => 'css', 'title' => __( 'CSS Class Name', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 22, 'help_text' => __( 'Provide a container class name for this field.', 'weforms' ), ), ); if ( $is_meta ) { $common_properties[] = array( 'name' => 'name', 'title' => __( 'Meta Key', 'weforms' ), 'type' => 'text-meta', 'section' => 'basic', 'priority' => 11, 'help_text' => __( 'Name of the meta key this field will save to', 'weforms' ), ); } return $common_properties; } /** * Common properties of a text input field * * @param boolean $word_restriction * * @return array */ public static function get_default_text_option_settings( $word_restriction = false ) { $properties = array( array( 'name' => 'placeholder', 'title' => __( 'Placeholder text', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 10, 'help_text' => __( 'Text for HTML5 placeholder attribute', 'weforms' ), ), array( 'name' => 'default', 'title' => __( 'Default value', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 11, 'help_text' => __( 'The default value this field will have', 'weforms' ), ), array( 'name' => 'size', 'title' => __( 'Size', 'weforms' ), 'type' => 'text', 'variation' => 'number', 'section' => 'advanced', 'priority' => 20, 'help_text' => __( 'Size of this input field', 'weforms' ), ), ); if ( $word_restriction ) { $properties[] = array( 'name' => 'word_restriction', 'title' => __( 'Word Restriction', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 15, 'help_text' => __( 'Numebr of words the author to be restricted in', 'weforms' ), ); } return apply_filters( 'wpuf-form-builder-common-text-fields-properties', $properties ); } /** * Option data for option based fields * * @param boolean $is_multiple * * @return array */ public function get_default_option_dropdown_settings( $is_multiple = false ) { return array( 'name' => 'options', 'title' => __( 'Options', 'wpuf' ), 'type' => 'option-data', 'is_multiple' => $is_multiple, 'section' => 'basic', 'priority' => 12, 'help_text' => __( 'Add options for the form field', 'wpuf' ), ); } /** * Common properties of a textarea field * * @return array */ public function get_default_textarea_option_settings() { return array( array( 'name' => 'rows', 'title' => __( 'Rows', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 10, 'help_text' => __( 'Number of rows in textarea', 'weforms' ), ), array( 'name' => 'cols', 'title' => __( 'Columns', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 11, 'help_text' => __( 'Number of columns in textarea', 'weforms' ), ), array( 'name' => 'placeholder', 'title' => __( 'Placeholder text', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 12, 'help_text' => __( 'Text for HTML5 placeholder attribute', 'weforms' ), 'dependencies' => array( 'rich' => 'no' ) ), array( 'name' => 'default', 'title' => __( 'Default value', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 13, 'help_text' => __( 'The default value this field will have', 'weforms' ), ), array( 'name' => 'rich', 'title' => __( 'Textarea', 'weforms' ), 'type' => 'radio', 'options' => array( 'no' => __( 'Normal', 'weforms' ), 'yes' => __( 'Rich textarea', 'weforms' ), 'teeny' => __( 'Teeny Rich textarea', 'weforms' ), ), 'section' => 'advanced', 'priority' => 14, 'default' => 'no', ), array( 'name' => 'word_restriction', 'title' => __( 'Word Restriction', 'weforms' ), 'type' => 'text', 'section' => 'advanced', 'priority' => 15, 'help_text' => __( 'Numebr of words the author to be restricted in', 'weforms' ), ), ); } /* |-------------------------------------------------------------------------- | Field helper methods |-------------------------------------------------------------------------- | | Various helper method for rendering form fields */ public function print_list_attributes( $field ) { $label = isset( $field['label'] ) ? $field['label'] : ''; $el_name = !empty( $field['name'] ) ? $field['name'] : ''; $class_name = !empty( $field['css'] ) ? ' ' . $field['css'] : ''; printf( 'class="wpuf-el %s%s" data-label="%s"', $el_name, $class_name, $label ); } /** * Prints form input label * * @param array $attr * @param integer $form_id */ function print_label( $field, $form_id = 0 ) { ?>
is_required( $field ) ) { return ' *'; } } /** * Prints help text for a field * * @param array $field */ function help_text( $field ) { if ( empty( $field['help'] ) ) { return; } ?>