• Resolved kaosuay

    (@kaosuay)


    Error message is shown, and I can not push submit button.

    Warning: Undefined array key “restriction_to” in /wp-content/plugins/wp-user-frontend/includes/fields/class-field-textarea.php on line 92

    Please tell me how to solve it?

    WordPress ver: 6.0.3

    WP User Frontend ver: 3.5.29

    <?php
    
    /**
      * Textarea Field Class
      */
    class WPUF_Form_Field_Textarea extends WPUF_Field_Contract {
    
        public function __construct() {
            $this->name       = __( 'Textarea', 'wp-user-frontend' );
            $this->input_type = 'textarea_field';
            $this->icon       = 'paragraph';
        }
    
         /**
          * Render the Textarea field
          *
          * @param array  $field_settings
          * @param int    $form_id
          * @param string $type
          * @param int    $post_id
          *
          * @return void
          */
        public function render( $field_settings, $form_id, $type = 'post', $post_id = null ) {
            if ( isset( $post_id ) && $post_id != '0' ) {
                if ( $this->is_meta( $field_settings ) ) {
                    $value = $this->get_meta( $post_id, $field_settings['name'], $type );
                }
            } else {
                $value = $field_settings['default'];
            }
    
            $req_class   = ( $field_settings['required'] == 'yes' ) ? 'required' : 'rich-editor';
            $textarea_id = $field_settings['name'] ? $field_settings['name'] . '_' . $form_id : 'textarea_';
    
            $this->field_print_label( $field_settings, $form_id ); ?>
    
                 <?php if ( in_array( $field_settings['rich'], [ 'yes', 'teeny' ] ) ) { ?>
                    <div class="wpuf-fields wpuf-rich-validation <?php printf( 'wpuf_%s_%s', esc_attr( $field_settings['name'] ), esc_attr( $form_id ) ); ?>" data-type="rich" data-required="<?php echo esc_attr( $field_settings['required'] ); ?>" data-id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>" data-name="<?php echo esc_attr( $field_settings['name'] ); ?>">
                <?php } else { ?>
                    <div class="wpuf-fields">
                <?php } ?>
    
                    <?php
                        $tinymce_settings = wpuf_filter_editor_toolbar( $field_settings );
    
                    if ( ( $field_settings['rich'] === 'teeny' || $field_settings['rich'] === 'yes' ) ) {
                        $editor_settings = [
                            'textarea_rows' => $field_settings['rows'],
                            'quicktags'     => false,
                            'media_buttons' => false,
                            'editor_class'  => $req_class,
                            'textarea_name' => $field_settings['name'],
                        ];
    
                        if ( ! empty( $tinymce_settings ) ) {
                            $editor_settings['tinymce'] = $tinymce_settings;
                        }
    
                        if ( $field_settings['rich'] === 'teeny' ) {
                            $editor_settings['teeny'] = true;
                        }
    
                        $editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings );
                        wp_editor( $value, $textarea_id, $editor_settings );
                    } else {
                        ?>
                        <textarea
                            class="textareafield <?php echo esc_attr( ' wpuf_' . $field_settings['name'] . '_' . $form_id ); ?>"
                            id="<?php echo esc_attr( $field_settings['name'] . '_' . $form_id ); ?>"
                            name="<?php echo esc_attr( $field_settings['name'] ); ?>"
                            data-required="<?php echo esc_attr( $field_settings['required'] ); ?>"
                            data-type="textarea"
                            placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>"
                            rows="<?php echo esc_attr( $field_settings['rows'] ); ?>"
                            cols="<?php echo esc_attr( $field_settings['cols'] ); ?>"
                        ><?php echo esc_textarea( $value ); ?></textarea>
                        <span class="wpuf-wordlimit-message wpuf-help"></span>
    
                            <?php
                    }
                    ?>
    
                     <?php
                        $this->help_text( $field_settings );
                        if ( isset( $field_settings['content_restriction'] ) && $field_settings['content_restriction'] ) {
                                    $this->check_content_restriction_func(
                                        $field_settings['content_restriction'],
                                        ! empty( $field_settings['rich'] ) ? $field_settings['rich'] : 'no',
                                        $field_settings['name'] . '_' . $form_id,
                                        $field_settings['restriction_type'],
                                        $field_settings['restriction_to']
                                    );
                        }
                        ?>
    
             <?php
                $this->after_field_print_label();
        }
    
         /**
          * Get field options setting
          *
          * @return array
          */
        public function get_options_settings() {
            $default_options      = $this->get_default_option_settings();
            $default_text_options = $this->get_default_textarea_option_settings();
    
            return array_merge( $default_options, $default_text_options );
        }
    
         /**
          * Get the field props
          *
          * @return array
          */
        public function get_field_props() {
            $defaults = $this->default_attributes();
            $props    = [
                'input_type'        => 'textarea',
                'label'             => __( 'Textarea', 'wp-user-frontend' ),
                'is_meta'           => 'yes',
                'rows'              => 5,
                'cols'              => 25,
                'rich'              => 'no',
                'id'                => 0,
                'is_new'            => true,
                'show_in_post'      => 'yes',
                'hide_field_label'  => 'no',
                'restriction_type'  => 'character',
                'restriction_to'   => 'max',
                'text_editor_control' => [],
            ];
    
            return array_merge( $defaults, $props );
        }
    
         /**
          * Prepare entry
          *
          * @param $field
          *
          * @return mixed
          */
        public function prepare_entry( $field ) {
            check_ajax_referer( 'wpuf_form_add' );
    
            $field = isset( $_POST[ $field['name'] ] ) ? sanitize_text_field( wp_unslash( $_POST[ $field['name'] ] ) ) : '';
            return trim( $field );
        }
    
         /**
          * Render textarea field data
          *
          * @since 3.3.0
          *
          * @param mixed $data
          * @param array $field
          *
          * @return string
          */
        public function render_field_data( $data, $field ) {
            $data      = implode( ',', $data );
            $hide_label = isset( $field['hide_field_label'] )
               ? wpuf_validate_boolean( $field['hide_field_label'] )
               : false;
    
            if ( empty( $data ) ) {
                return '';
            }
    
            $container_classnames = [ 'wpuf-field-data', 'wpuf-field-data-' . $this->input_type ];
    
            ob_start();
            ?>
                <li class="<?php echo esc_attr( implode( ' ', $container_classnames ) ); ?>">
                   <?php if ( ! $hide_label ) : ?>
                        <label><?php echo esc_html( $field['label'] ); ?>:</label>
                    <?php endif; ?>
                   <?php echo wp_kses_post( wpautop( make_clickable( $data ) ) ); ?>
                </li>
             <?php
                return ob_get_clean();
        }
    
         /**
          * Sanitize field data
          *
          * @since 3.3.1
          *
          * @param string $data
          * @param array  $field
          *
          * @return string
          */
        public function sanitize_field_data( $data, $field ) {
            return wp_kses_post( $data );
        }
    }

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @kaosuay,

    Did you check the plugin conflict on your website? because It looks like there might have a conflict on your site. So, this will need to check if that is coming from any other plugin.

    Please make sure that you’ve already done the conflict test. If you haven’t yet, please follow the below procedures for testing purposes.

    • Please deactivate all plugins except the latest version of the WP User Frontend Plugin.
    • Use a default theme such as twenty-twenty or twenty-twenty-one.
    • Use the default language on your website.
    • Make sure you’re using PHP Version 8.0 on your website.
    • Clear your site cache as well as the browser cache and try the process again.
    • If you are still having the problem, then kindly contact through the website for further assistance.

      Regards!

    Thread Starter kaosuay

    (@kaosuay)

    Thank you for your reply.

    I will check your advice.

    Regards!

    You’re most welcome 🙂
    Hope your issue will be resolved.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Error message is shown’ is closed to new replies.