Title: Motiforms
Author: kierzniak
Published: <strong>2017 年 11 月 10 日</strong>
Last modified: 2017 年 11 月 10 日

---

搜尋外掛

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

![](https://s.w.org/plugins/geopattern-icon/motiforms.svg)

# Motiforms

 由 [kierzniak](https://profiles.wordpress.org/kierzniak/) 開發

[下載](https://downloads.wordpress.org/plugin/motiforms.0.1.0.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/motiforms/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/motiforms/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/motiforms/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/motiforms/#developers)

 [技術支援](https://wordpress.org/support/plugin/motiforms/)

## 外掛說明

#### WARNING

If you are not developer this plugin is not for you. Motiforms do not provide any
WordPress admin interface to creating forms.

#### Features

 * Handle form logic
 * Field sanitization
 * Field validation
 * Built in html rendering helpers
 * Flexibility
 * Based on advanced Symfony framework

#### Get started

To create simple contact form paste code bellow to your functions.php file. And 
paste `[contact]` shortcode to your contact page.

    ```
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Symfony\Component\Form\Extension\Core\Type\EmailType;
    use Symfony\Component\Form\Extension\Core\Type\TextareaType;
    use Symfony\Component\Form\Extension\Core\Type\SubmitType;

    class ContactForm {

        /**
         * Form instance
         *
         * FormType
         */
        private $form;

        /**
         * ContacForm constructor
         *
         * @return ContacForm
         */
        public function __construct() {

            $this->define_hooks();
        }

        /**
         * Create and process contact form
         *
         * This method is executed by wp action hook.
         * It will be executed only on page which has contact
         * shortcode.
         *
         * @return void
         */
        public function controller() {

            global $post;

            // Check if current view is page and page has content shortcode
            if ( is_page() && has_shortcode( $post->post_content, 'contact' ) ) {

                $factory = mf_get_factory();

                // Create form
                $this->form = $factory->create();

                // Add fields to form
                $this->form->add( 'full_name', TextType::class );
                $this->form->add( 'email', EmailType::class );
                $this->form->add( 'message', TextareaType::class );
                $this->form->add( 'submit', SubmitType::class );

                // Get request object
                $request = mf_get_request();

                // Handle request
                $this->form->handleRequest( $request );

                // Check if form is valid
                if ( $this->form->isSubmitted() && $this->form->isValid() ) {

                    // Get data from the form
                    $data = $this->form->getData();

                    // Define filters
                    $filters = array(
                        'full_name' => FILTER_SANITIZE_STRING,
                        'email' => FILTER_SANITIZE_STRING | FILTER_SANITIZE_EMAIL,
                        'message' => FILTER_SANITIZE_STRING,
                    );

                    // Fields sanitization
                    $sanitized_data = filter_var_array( $data, $filters );

                    // Perform action with form data e.g. send an e-mail

                    // Redirect user with success parameter to prevent double submitting form
                    wp_safe_redirect( $this->get_redirect_url() );
                }
            }
        }

        /**
         * Render contact form.
         *
         * This method is executed by contact shortcode.
         *
         * @return string
         */
        public function render() {

            $success =  filter_input( INPUT_GET, 'success', FILTER_SANITIZE_NUMBER_INT );

            if( '1' === $success ) {
                return sprintf('<h2>%s</h2>', __('Thank you for submitting the form. We will contact you shortly.') );
            }

            $form_view = $this->form->createView();

            $engine = mf_get_engine();

            return $engine['form']->form( $form_view, array('attr' => array('novalidate' => 'novalidate') ) );

        }

        /**
         * Method executed by constructor to define hooks and
         * create and render contact form.
         *
         * @return void
         */
        private function define_hooks() {

            add_action( 'wp', array( $this, 'controller' ) );

            add_shortcode( 'contact', array( $this, 'render' ) );
        }

        /**
         * Build url for form redirect
         *
         * @return string
         */
        private function get_redirect_url() {

            $url = get_permalink();

            $query = parse_url($url, PHP_URL_QUERY);

            // Returns a string if the URL has parameters or NULL if not
            if ($query) {
                $url .= '&success=1';
            } else {
                $url .= '?success=1';
            }

            return $url;
        }
    }

    // Initialize contact form
    new ContactForm();
    ```

## 安裝方式

 1. Visit Plugins > Add New
 2. Search for “Motiforms”
 3. Install and activate “Motiforms”
 4. Go to [get started](https://github.com/motivast/motiforms#user-content-get-started)
    section to see a simple example.

or

 1. Download plugin from wordpres.org repository or [release section](https://github.com/motivast/motiforms/releases/latest).
 2. Upload the motiforms directory to your /wp-content/plugins/ directory
 3. Activate the plugin through the”‘Plugins” menu in WordPress
 4. Go to [get started](https://github.com/motivast/motiforms#user-content-get-started)
    section to see a simple example.

## 常見問題集

  Installation Instructions

 1. Visit Plugins > Add New
 2. Search for “Motiforms”
 3. Install and activate “Motiforms”
 4. Go to [get started](https://github.com/motivast/motiforms#user-content-get-started)
    section to see a simple example.

or

 1. Download plugin from wordpres.org repository or [release section](https://github.com/motivast/motiforms/releases/latest).
 2. Upload the motiforms directory to your /wp-content/plugins/ directory
 3. Activate the plugin through the”‘Plugins” menu in WordPress
 4. Go to [get started](https://github.com/motivast/motiforms#user-content-get-started)
    section to see a simple example.

  Where I can find documentation?

Documentation for Motiforms can be found on github [wiki pages](https://github.com/motivast/motiforms/wiki).

## 使用者評論

這個外掛目前沒有任何使用者評論。

## 參與者及開發者

以下人員參與了開源軟體〈Motiforms〉的開發相關工作。

參與者

 *   [ kierzniak ](https://profiles.wordpress.org/kierzniak/)

[將〈Motiforms〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/motiforms)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/motiforms/)、查看
[SVN 存放庫](https://plugins.svn.wordpress.org/motiforms/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/motiforms/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/motiforms/)。

## 變更記錄

#### 0.1.0

 * Motiforms

## 中繼資料

 *  版本 **0.1.0**
 *  最後更新 **9 年前**
 *  啟用安裝數 **10+**
 *  WordPress 版本需求 ** 3.8 或更新版本 **
 *  已測試相容的 WordPress 版本 **4.8.28**
 *  語言
 * [English (US)](https://wordpress.org/plugins/motiforms/)
 * 標籤:
 * [contact form](https://tw.wordpress.org/plugins/tags/contact-form/)[custom form](https://tw.wordpress.org/plugins/tags/custom-form/)
   [form](https://tw.wordpress.org/plugins/tags/form/)[forms](https://tw.wordpress.org/plugins/tags/forms/)
   [symfony](https://tw.wordpress.org/plugins/tags/symfony/)
 *  [進階檢視](https://tw.wordpress.org/plugins/motiforms/advanced/)

## 評分

這個項目尚無任何評論記錄。

[Your review](https://wordpress.org/support/plugin/motiforms/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/motiforms/reviews/)

## 參與者

 *   [ kierzniak ](https://profiles.wordpress.org/kierzniak/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/motiforms/)