将用户添加到我的网站(SMS)的openVBX twilio订阅列表中?

时间:2014-02-19 15:38:27

标签: forms sms twilio

我在Twilio中使用OpenVBX。当我们使用关键字将新订阅者发送到我的号码时,我可以将新订阅者添加到SMS列表中。这个功能都内置在OpenVBX中(带插件),但我没有找到的是如何从我网站上的表单条目中添加一个数字。谁知道我怎么做到这一点?

1 个答案:

答案 0 :(得分:0)

所以我把它放在页脚区域。

<script type="text/javascript">
  $(document).ready(function() {

    $('.phone_us').mask('(000) 000-0000');

    $('.cep_with_callback').mask('00000-000', {onComplete: function(cep) {
        console.log('Mask is done!:', cep);
      },
       onKeyPress: function(cep, event, currentField, options){
        console.log('An key was pressed!:', cep, ' event: ', event, 'currentField: ', currentField.attr('class'), ' options: ', options);
      }
    });

    $('.crazy_cep').mask('00000-000', {onKeyPress: function(cep){
      var masks = ['00000-000', '0-00-00-00'];
        mask = (cep.length>7) ? masks[1] : masks[0];
      $('.crazy_cep').mask(mask, this);
    }});

    $('.cpf').mask('000.000.000-00', {reverse: true});
    $('.money').mask('#.##0,00', {reverse: true, maxlength: false});

    var SaoPauloCelphoneMask = function(phone, e, currentField, options){
      return phone.match(/^(\(?11\)? ?9(5[0-9]|6[0-9]|7[01234569]|8[0-9]|9[0-9])[0-9]{1})/g) ? '(00) 00000-0000' : '(00) 0000-0000';
    };

    $(".sp_celphones").mask('(00) 00009-0000');

    $(".bt-mask-it").click(function(){
      $(".mask-on-div").mask("000.000.000-00");
      $(".mask-on-div").fadeOut(500).fadeIn(500)
    })

    $('pre').each(function(i, e) {hljs.highlightBlock(e)});
  });
</script>

然后我通过连接到数据库并将电话号码输入到我在OpenVBX中创建的列表中来处理它。

<?php

    $config['db'] = array(
        'host'      => 'internal-servername.com',
        'username'  => 'dbUsername',
        'password'  => 'dbPassword',
        'dbname'    => 'dbName'
    );

    $errors = array(); //To store errors
    $form_data = array(); //Pass back the data to `form.php`

    $fixedNumber = preg_replace("/\D/", "", $_POST['name']);
    preg_replace("/\D/", "", $input_lines);
    $finalVersion = '+1' . $fixedNumber;


    /* Validate the form on server side */
    if (empty($_POST['name'])) { //Name cannot be empty
        $errors['name'] = 'Number cannot be blank';
    }
    if (strlen($_POST['name']) < 14 ) { //Name cannot be empty
        $errors['name'] = 'Something went wrong. Check the number and try again.';
    }

    if (!empty($errors)) { //If errors in validation
        $form_data['success'] = false;
        $form_data['errors']  = $errors;
    } else { //If not, process the form, and return true on success
        $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //need these attributes in order to use Try - Catch. 
        $q = $db->prepare("INSERT INTO `db171349_phones`.`subscribers` (`id`, `list`, `value`, `joined`) VALUES (NULL, '3', '$finalVersion', UNIX_TIMESTAMP())");
        $q->execute();
        $form_data['success'] = true;
        $form_data['posted'] = "Thanks! We'll let you know as soon as the book is available.";
    }

    //Return the data back to form.php
    echo json_encode($form_data);
?>