# double-opt-in/2.12/core/UIPageForm.class.php

Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification, version 2.12. 105 lines.

- Page: https://pluginprobe.com/plugins/double-opt-in/2.12/code/core/UIPageForm.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/2.12/raw/core/UIPageForm.class.php
- Modified: 2022-12-16T11:04:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/double-opt-in/2.12/code/core/UIPageForm.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
    if (!defined('ABSPATH')) {
        exit;
    }

    abstract class UIPageForm extends UIPage
    {
        /**
         * define if the button for the submit should be displayed or not.
         * if hidden, the wp_nonce will also be removed. Ensure you handle
         * the save process on your own. The onSave function will still be called
         *
         * @var bool
         */
        private $hide_submit_button = false;

        /**
         * @return mixed
         */
        protected function maybeSave()
        {
            if (isset($_POST['doi_settings_nonce']) && wp_verify_nonce($_POST['doi_settings_nonce'], 'doi_settings_action')) {
                $settings = CF7DoubleOptIn::getInstance()->getSettings();

                $settings = apply_filters('f12_cf7_doubleoptin_ui_' . $this->slug . '_before_on_save', $settings);

                $settings = $this->onSave($settings);

                $settings = apply_filters('f12_cf7_doubleoptin_ui_' . $this->slug . '_after_on_save', $settings);

                update_option('f12-doi-settings', $settings);

                Messages::getInstance()->add(__('Settings updated', 'double-opt-in'), 'success');
            }
        }

        /**
         * Option to hide the submit button
         *
         * @param bool $hide
         *
         * @return void
         */
        protected function hideSubmitButton($hide)
        {
            $this->hide_submit_button = $hide;
        }

        /**
         * Returns true if the button should be hidden.
         *
         * @return bool
         */
        protected function isSubmitButtonHidden()
        {
            return $this->hide_submit_button;
        }

        /**
         * Update the settings and return them
         *
         * @param $settings
         *
         * @return array
         */
        protected abstract function onSave($settings);

        /**
         * @return void
         * @private WordPress HOOK
         */
        public function renderContent($slug, $page)
        {
            if ($this->slug != $page) {
                return;
            }

            $this->maybeSave();

            $settings = CF7DoubleOptIn::getInstance()->getSettings();

            echo esc_html(Messages::getInstance()->getAll());
            ?>
            <div class="box">
                <form action="" method="post">
                    <?php
                    do_action('f12_cf7_doubleoptin_ui_' . $page . '_before_content', $settings);
                    $this->theContent($slug, $page, $settings);
                    do_action('f12_cf7_doubleoptin_ui_' . $page . '_after_content', $settings);


                    if (!$this->isSubmitButtonHidden()):
                        wp_nonce_field('doi_settings_action', 'doi_settings_nonce');
                        ?>
                        <input type="submit" name="doubleoptin-settings-submit" class="button"
                               value=" <?php _e('Save', 'double-opt-in'); ?>"/>
                    <?php endif; ?>
                </form>
            </div>
            <?php
        }
    }
}
```
