Plugin Directory

Changeset 1538202


Ignore:
Timestamp:
11/22/2016 10:02:27 AM (9 years ago)
Author:
sendmachine
Message:

subscribe form - required fields extra checks

Location:
sendmachine
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • sendmachine/tags/1.0.13/includes/sendmachine_defaults.php

    r1538133 r1538202  
    2323                "message_invalid_email" => __('Please provide a valid email address.', SM_LANGUAGE_DOMAIN),
    2424                "label_submit_button" => __('Subscribe', SM_LANGUAGE_DOMAIN),
     25                "message_required_field" => __('Please provide all the required field data.', SM_LANGUAGE_DOMAIN),
    2526                "checkbox_register" => 1,
    2627                "checkbox_comment" => 0,
  • sendmachine/tags/1.0.13/includes/sendmachine_subscribe_manager.php

    r1538133 r1538202  
    165165        $is_ajax = isset($data['is_sm_ajax_request']) ? $data['is_sm_ajax_request'] : NULL;
    166166        $sm_api = Sm_wp::instance()->sm;
     167        $defaults = Sm_defaults::defaults();
    167168
    168169        if ($action == "subscribe_form") {
     
    174175           
    175176            $fields = $this->app['list']['fields'];
     177            if(!$fields) {
     178                $msg = array("message" => $this->app['list']['message_not_subscribed'], "status" => "error");
     179                echo json_encode($msg);
     180                exit();
     181            }
    176182           
    177183            $fn = array();
     184            $has_error = false;
    178185            foreach($fields as $f) $fn[] = $f['name'];
    179186
    180187            foreach($data as $k => $v) {
    181                 if(!in_array($k,$fn)) unset($data[$k]);
    182             }
    183            
    184             if ($sm_api->get_recipient($this->app['list']['id'], $email))
     188               
     189                if(!in_array($k,$fn)) {
     190                    unset($data[$k]);
     191                    continue;
     192                }
     193               
     194                foreach($fields as $field) {
     195                    if($field['name'] === $k) {
     196                        if($field['required'] && !$v) {
     197                            $has_error = true;
     198                        }
     199                        break;
     200                    }
     201                }
     202            }
     203           
     204            if ($has_error) {
     205               
     206                $_msg = isset($this->app['list']['message_required_field']) ? $this->app['list']['message_required_field'] : $defaults['list']['message_required_field'];
     207               
     208                $msg = array("message" => $_msg, "status" => "error");
     209                echo json_encode($msg);
     210                exit();
     211            }
     212
     213            if ($sm_api->get_recipient($this->app['list']['id'], $email)) {
     214               
    185215                $msg = array("message" => $this->app['list']['message_subscriber_exists'], "status" => "error");
    186             elseif ($resp = $sm_api->subscribe($this->app['list']['id'], $email, $data)) {
     216            } elseif ($resp = $sm_api->subscribe($this->app['list']['id'], $email, $data)) {
    187217
    188218                if (is_user_logged_in()) add_user_meta( get_current_user_id(), SM_USER_META_NAME, 1);
     
    192222                $msg = array("message" => $this->app['list']['message_success_subscribe'], "status" => "success");
    193223            }
    194             else
     224            else {
     225               
    195226                $msg = array("message" => $this->app['list']['message_not_subscribed'], "status" => "error");
     227            }
    196228
    197229            if ($is_ajax) { echo json_encode($msg); exit(); }
     
    221253            if (is_user_logged_in() && $resp) add_user_meta( get_current_user_id(), SM_USER_META_NAME, 1);
    222254        }
    223         elseif ($action == "sync_users"){
     255        elseif ($action == "sync_users") {
    224256           
    225257            if (empty($this->app['list']['id'])) {
  • sendmachine/tags/1.0.13/readme.txt

    r1538133 r1538202  
    44Requires at least: 3.2.1
    55Tested up to: 4.6
    6 Stable tag: 1.0.12
     6Stable tag: 1.0.13
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9696== Changelog ==
    9797
     98= 1.0.13 =
     99* Subscribe required fields limitation
     100
    98101= 1.0.12 =
    99102* Extra checks for invalid email address
  • sendmachine/tags/1.0.13/sendmachine_wp.php

    r1538133 r1538202  
    55  Plugin URI: https://www.sendmachine.com
    66  Description: The official Sendmachine plugin featuring subscribe forms, users sync, news feed, email sending and transactional campaigns.
    7   Version: 1.0.12
     7  Version: 1.0.13
    88  Author: Sendmachine team
    99  Author URI: http://developers.sendmachine.com/
  • sendmachine/tags/1.0.13/sendmachine_wp_admin.php

    r1538133 r1538202  
    9191            if(!isset($this->app['list']['label_submit_button'])) {
    9292                $this->app['list']['label_submit_button'] = $defaults['list']['label_submit_button'];
     93            }
     94           
     95            if(!isset($this->app['list']['message_required_field'])) {
     96                $this->app['list']['message_required_field'] = $defaults['list']['message_required_field'];
    9397            }
    9498
  • sendmachine/tags/1.0.13/views/wp_sm_list_settings.php

    r1538133 r1538202  
    128128                <tr>
    129129                    <td class='sm_row_title'>
     130                        <span><?php _e("Required fields error", SM_LANGUAGE_DOMAIN); ?></span>
     131                    </td>
     132                    <td class='sm_row_content' colspan="2">
     133                        <input type="text" name="update[list][message_required_field]" class="widefat" value="<?php echo $this->app['list']['message_required_field']; ?>" />
     134                    </td>
     135                </tr>
     136                <tr>
     137                    <td class='sm_row_title'>
    130138                        <span><?php _e("Submit button label", SM_LANGUAGE_DOMAIN); ?></span>
    131139                    </td>
  • sendmachine/trunk/includes/sendmachine_defaults.php

    r1538133 r1538202  
    2323                "message_invalid_email" => __('Please provide a valid email address.', SM_LANGUAGE_DOMAIN),
    2424                "label_submit_button" => __('Subscribe', SM_LANGUAGE_DOMAIN),
     25                "message_required_field" => __('Please provide all the required field data.', SM_LANGUAGE_DOMAIN),
    2526                "checkbox_register" => 1,
    2627                "checkbox_comment" => 0,
  • sendmachine/trunk/includes/sendmachine_subscribe_manager.php

    r1538133 r1538202  
    165165        $is_ajax = isset($data['is_sm_ajax_request']) ? $data['is_sm_ajax_request'] : NULL;
    166166        $sm_api = Sm_wp::instance()->sm;
     167        $defaults = Sm_defaults::defaults();
    167168
    168169        if ($action == "subscribe_form") {
     
    174175           
    175176            $fields = $this->app['list']['fields'];
     177            if(!$fields) {
     178                $msg = array("message" => $this->app['list']['message_not_subscribed'], "status" => "error");
     179                echo json_encode($msg);
     180                exit();
     181            }
    176182           
    177183            $fn = array();
     184            $has_error = false;
    178185            foreach($fields as $f) $fn[] = $f['name'];
    179186
    180187            foreach($data as $k => $v) {
    181                 if(!in_array($k,$fn)) unset($data[$k]);
    182             }
    183            
    184             if ($sm_api->get_recipient($this->app['list']['id'], $email))
     188               
     189                if(!in_array($k,$fn)) {
     190                    unset($data[$k]);
     191                    continue;
     192                }
     193               
     194                foreach($fields as $field) {
     195                    if($field['name'] === $k) {
     196                        if($field['required'] && !$v) {
     197                            $has_error = true;
     198                        }
     199                        break;
     200                    }
     201                }
     202            }
     203           
     204            if ($has_error) {
     205               
     206                $_msg = isset($this->app['list']['message_required_field']) ? $this->app['list']['message_required_field'] : $defaults['list']['message_required_field'];
     207               
     208                $msg = array("message" => $_msg, "status" => "error");
     209                echo json_encode($msg);
     210                exit();
     211            }
     212
     213            if ($sm_api->get_recipient($this->app['list']['id'], $email)) {
     214               
    185215                $msg = array("message" => $this->app['list']['message_subscriber_exists'], "status" => "error");
    186             elseif ($resp = $sm_api->subscribe($this->app['list']['id'], $email, $data)) {
     216            } elseif ($resp = $sm_api->subscribe($this->app['list']['id'], $email, $data)) {
    187217
    188218                if (is_user_logged_in()) add_user_meta( get_current_user_id(), SM_USER_META_NAME, 1);
     
    192222                $msg = array("message" => $this->app['list']['message_success_subscribe'], "status" => "success");
    193223            }
    194             else
     224            else {
     225               
    195226                $msg = array("message" => $this->app['list']['message_not_subscribed'], "status" => "error");
     227            }
    196228
    197229            if ($is_ajax) { echo json_encode($msg); exit(); }
     
    221253            if (is_user_logged_in() && $resp) add_user_meta( get_current_user_id(), SM_USER_META_NAME, 1);
    222254        }
    223         elseif ($action == "sync_users"){
     255        elseif ($action == "sync_users") {
    224256           
    225257            if (empty($this->app['list']['id'])) {
  • sendmachine/trunk/readme.txt

    r1538133 r1538202  
    44Requires at least: 3.2.1
    55Tested up to: 4.6
    6 Stable tag: 1.0.12
     6Stable tag: 1.0.13
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9696== Changelog ==
    9797
     98= 1.0.13 =
     99* Subscribe required fields limitation
     100
    98101= 1.0.12 =
    99102* Extra checks for invalid email address
  • sendmachine/trunk/sendmachine_wp.php

    r1538133 r1538202  
    55  Plugin URI: https://www.sendmachine.com
    66  Description: The official Sendmachine plugin featuring subscribe forms, users sync, news feed, email sending and transactional campaigns.
    7   Version: 1.0.12
     7  Version: 1.0.13
    88  Author: Sendmachine team
    99  Author URI: http://developers.sendmachine.com/
  • sendmachine/trunk/sendmachine_wp_admin.php

    r1538133 r1538202  
    9191            if(!isset($this->app['list']['label_submit_button'])) {
    9292                $this->app['list']['label_submit_button'] = $defaults['list']['label_submit_button'];
     93            }
     94           
     95            if(!isset($this->app['list']['message_required_field'])) {
     96                $this->app['list']['message_required_field'] = $defaults['list']['message_required_field'];
    9397            }
    9498
  • sendmachine/trunk/views/wp_sm_list_settings.php

    r1538133 r1538202  
    128128                <tr>
    129129                    <td class='sm_row_title'>
     130                        <span><?php _e("Required fields error", SM_LANGUAGE_DOMAIN); ?></span>
     131                    </td>
     132                    <td class='sm_row_content' colspan="2">
     133                        <input type="text" name="update[list][message_required_field]" class="widefat" value="<?php echo $this->app['list']['message_required_field']; ?>" />
     134                    </td>
     135                </tr>
     136                <tr>
     137                    <td class='sm_row_title'>
    130138                        <span><?php _e("Submit button label", SM_LANGUAGE_DOMAIN); ?></span>
    131139                    </td>
Note: See TracChangeset for help on using the changeset viewer.