V
V
Vladimir2016-11-01 14:51:36
MODX
Vladimir, 2016-11-01 14:51:36

How to send sms (or in general how to execute any php code) while submitting a modx form?

Until recently, I sent SMS with the data of the completed form and recorded the same form data in the google spreadsheet simply through
an external form handler written in php :) in which this was solved simply, there were 2 codes after the form was successfully submitted)
this is a call to the sms.ru API

<?php
$ch = curl_init("http://sms.ru/sms/send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(

  "api_id"		=>	"9999999999999",
  "to"			=>	"8888888888888",
  "text"		=>	$name  ." ". $phone

));
$body = curl_exec($ch);
curl_close($ch);

This threw data into a google spreadsheet
$nik =$getdata['name']['value'];
$tell=$getdata['tell']['value'];
$mile=$getdata['e-mail']['value'];
$text=$getdata['text']['value'];
$chek=$getdata['checkbox']['value']." ". $getdata['radio']['value']." " . $getdata['select']['value'];
$utm=$getdata['utm-name']['value'];

// формируем запись в нашу таблицу google
$url = "99999999999999999999999999999999999999999999999999999999";
$_POST['fio'] = $nik;
$_POST['tell']=$tell;
$_POST['chek']=$chek;
$_POST['e-mail']=$mile;
$_POST['text']=$text; 
$_POST['utm-name']=$utm;

$draftResponse = ",,4503709590584940035";

$pageHistory = "0";
$fbzx = "3880320875455510089";


$post_data = array (
"entry.404904442" => $_POST['fio'],
"entry.2144695223" => $_POST['tell'],
"entry.481061397" =>$_POST['chek'],
"entry.568776889" =>$_POST['e-mail'],
"entry.516856755" =>$_POST['text'],
"entry.592606563"=>$_POST['utm-name'],
"draftResponse" => "[,,4503709590584940035;]",

"pageHistory" => "0",
"fbzx" => "4503709590584940035"
);
// заносим данные в сам google
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// указываем, что у нас POST запрос
curl_setopt($ch, CURLOPT_POST, 1);
// добавляем переменные
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//заполняем таблицу google
$output = curl_exec($ch);
 
curl_close($ch);
//

I wanted to clean up crutches )
Installed formit , ajaxform
In principle, the form works, made it in a modal window, realized that it uses hooks to send mail and save the form data in the database.
In general, how to make the execution of these two scripts, I still didn’t get it) Tell me, I’m not very familiar with modx

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gregory, 2016-11-01
@gregst

probably create two snippets (1 for sms, 2 for google) and call formit with &hooks=`1,2`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question