Примери за Уебхуук PHP скриптове

March 28, 2022

Ако вече сте запознати с Уебхуук на Jotform, ето примерни скриптове, които може да искате да опитате.

Забележка: Не забравяйте да актуализирате имената на полетата в тези скриптове с имената на полетата от вашата форма.

Незабавно известяване по имейл – Получете незабавно известяване по имейл, използвайки вашия сървър за изпращане на имейли

//конвертиране json данни във php
$result=$_REQUEST[‘rawRequest’];
$obj=json_decode($result, true);
//Променете с вашите имейли
$emailfrom=“john@example.com”; //Sender or From Email
$emailto=“paul@example.com”; //Recipient, you can predefine or use a field value e.g. $obj[‘q4_email’]
$subject=“You’ve got a new submission”; //Email Subject Title
//Не редактирайте
$id=$_POST[‘submissionID’]; //Get submission ID
$submissionURL=‘https://www.jotform.com/submission/’.$id; //Construct submission URL
$headers=“From: “.$emailfrom.rn“;
$headers.=“Reply-To: “.$emailfrom.rn“; //Optional
$headers.=“MIME-Version: 1.0rn“;
$headers.=“Content-Type: text/html; charset=utf-8rn“;
//Нов метод за получаване на данни от страницата за подадени формуляри
$html=new DOMDocument;
$html->loadHTML(file_get_contents($submissionURL));
$body=$html->getElementsByTagName(‘body’)->item(0);
//получаваnе на html код след тага на тялото
foreach ($body->childNodesas$child){
    $html->appendChild($html->importNode($child, true));
}
//направете таблицата адаптивна, така че да изглежда добре на имейл
$body=$html->getElementsByTagName(‘table’);
foreach ($bodyas$width) {
    $width->setAttribute(‘width’, ‘100%’);
}
$body=$html->saveHTML();
//Изпратете имейл
@mail($emailto, $subject, $body, $headers);
?>

Код: http://pastebin.com/embed_iframe/AmG72bve

Примерен резултат по имейл:

Sample Email Result

SMS известие – Изпратете SMS след изпращаане на формата, използвайки API на вашия SMS доставчик


//Catch form field values
$result=$_REQUEST[‘rawRequest’];
$obj=json_decode($result, true);
//Replace your authentication key & credentials
$authKey=“YourAuthKey”;
$senderId=“102234”;
$route=“default”;
//Replace your form field names
$mobileNumber=$obj[‘q1_mobileNo’]; //mobile no. from form data
$message=urlencode($obj[‘q2_message’]); //message from form data
//Prepare you post parameters
$postData=array(
‘authkey’=>$authKey,
‘mobiles’=>$mobileNumber,
‘message’=>$message,
‘sender’=>$senderId,
‘route’=>$route
);
//Replace your API endpoint
$url=“http://mysmsapiproviders.com/sendhttp.php”;
// init the resource
$ch=curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL =>$url,
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_POST =>true,
CURLOPT_POSTFIELDS =>$postData
//,CURLOPT_FOLLOWLOCATION => true
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output=curl_exec($ch);
//Print error if any
if(curl_errno($ch)){
    echo‘error:’.curl_error($ch);
}
curl_close($ch);
echo$output;
?>

Код: http://pastebin.com/embed_iframe/0A558v0y

Форма към MySQL – Изпратете формовите данни във вашата MySQL база данни

//Replace with your DB Details

$servername=“localhost”;
$username=“YOUR_USERNAME_HERE”;
$password=“YOUR_PASSWORD_HERE”;
$dbname=“YOUR_DBNAME_HERE”;
$dbtable=“YOUR_DBTABLE_HERE”;
//Create connection
$mysqli=new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($mysqli->connect_error) {
    die(“Connection failed: “.$mysqli->connect_error);
}
//Get field values from the form
//Get unique submissionID – nothing to change here
$sid=$mysqli->real_escape_string($_REQUEST[‘submissionID’]);
//Get form field values and decode – nothing to change here
$fieldvalues=$_REQUEST[‘rawRequest’];
$obj=json_decode($fieldvalues, true);
//Replace the field names from your form here
$fname=$mysqli->real_escape_string($obj[‘q15_yourName’][first]);
$lname=$mysqli->real_escape_string($obj[‘q15_yourName’][last]);
$email=$mysqli->real_escape_string($obj[‘q16_yourEmail16’]);
$message=$mysqli->real_escape_string($obj[‘q17_yourMessage’]);
$result=$mysqli->query(“SELECT * FROM $dbtable WHERE sid = ‘$sid'”);
//If submission ID exist, update record
if ($result->num_rows>0) {
    $result=$mysqli->query(“UPDATE $dbtable SET firstname = ‘$fname’, lastname = ‘$lname’, email = ‘$email’, message = ‘$message’ WHERE sid = ‘$sid'”);
    echo“Existing Record Updated!”;
}
//If new submission, insert record
else{
    $result=$mysqli->query(“INSERT IGNORE INTO $dbtable (sid, firstname, lastname, email, message) VALUES (‘$sid’, ‘$fname’, ‘$lname’,’$email’,’$message’)”);
    echo“New Record Added!”;
    if ($result===false) {echo“SQL error:”.$mysqli->error;}
}
$mysqli->close();
?>

Известия за неуспех – Получавайте известия, когато формуляра не е изпратен до вашия имейл на получаване

Следният скрипт ще използва вашия SMTP хост по подразбиране за изпращане на имейли. Затова се уверете, че вашият уеб хост поддържа това, в противен случай функцията за поща няма да работи.


include“JotForm.php”;
$jotformAPI=new JotForm(“YOUR_JOTFORM_API_KEY_HERE”);    // Put your API Key here
$history=$jotformAPI->getHistory(“emails”, “lastWeek”);
$subid=$_REQUEST[‘submissionID’];
$submissionURL=‘https://www.jotform.com/submission/’.$subid; //Construct submission URL
$limit=1; //send the last failed notification – increase the number if you have multiple notifications
$results=array();
//Your emails here
$to=“johndoe@example.com”; //Replace with your recipient email
$from=“paulsmith@example.com”; //Replace with your FROM email
//change the subject title if you like
$subject=“View submission failed to be sent”;
//Don’t edit
$headers=“MIME-Version: 1.0”.rn“;
$headers.=“Content-type:text/html;charset=UTF-8”.rn“;
$headers.=‘From: <‘.$from.‘>’.rn“;
//Additional body message here (optional)
$msg1=“This submission has failed to be sent into your email.”;
//New method, get data from the submissions page
$html=new DOMDocument;
$html->loadHTML(file_get_contents($submissionURL));
$body=$html->getElementsByTagName(‘body’)->item(0);
//get html code after the body tag
foreach ($body->childNodesas$child){
    $html->appendChild($html->importNode($child, true));
}
//make the table responsive so it appears nicely on email
$body=$html->getElementsByTagName(‘table’);
foreach ($bodyas$width) {
    $width->setAttribute(‘width’, ‘100%’);
}
//don’t edit anything from here unless you know what you’re doing
foreach ($historyas$key=>$value) {        
    if ($value[‘status’] ==“IN BOUNCE/BLOCK LIST”||$value[‘status’] ==“FAILED”&&$value[‘submissionID’] ==$subid){
        if ($key==$limit1) {
            $body=    $msg1.
“;
            $body.=$html->saveHTML();                
            @mail($to, $subject, $body, $headers);
        }
    }
}
?>

Bounce Notifier
  • Код: https://pastebin.com/embed_iframe/uSsnsehh
  • Забележка: Заменете имейлите ОТ и ДО, както и вашия API ключ на Jotform в кода.
  • Важно: Този код изисква PHP клиентска библиотека от страницата за API на Jotform (или можете да я изтеглите от тук). Поставете файла JotForm.php в същата папка, съдържаща вашия PHP файл за известие за отскачане.

Ще публикуваме още примери от време на време. Ако имате някакви предложения или ако имате нужда от помощ с Уебхуук, можете да ги публикувате по-долу.

Беше ли това ръководство полезно?
Свържете се с екипа за поддръжка:

Нашият екип за поддръжка на клиенти е на разположение денонощно и средното ни време за реакция е между един и два часа.
С нашия екип можете да се свържете чрез:

Форум за поддръжка: https://www.jotform.com/answers/

Свържете се с поддръжката на Jotform: https://www.jotform.com/contact/

Jotform for Beginners

Get more done with powerful, easy-to-use online forms. Learn how in this helpful, free guide from Jotform.

Download the Book
Jotform for Beginners

Изпратете коментар:

Jotform Avatar
Този сайт е защитен от реКАПЧА и се прилагат Декларацията за поверителност и общите условия на Google.

Коментар:

Podo CommentБъдете първите, които коментират.
Access powerful form features with Jotform's free plan.
Access powerful form features with Jotform's free plan. Sign Up for Free!
Make an online form in minutes with Jotform.
Make an online form in minutes with Jotform. Create a Free Form
Discover Jotform’s powerful online form features.
Discover Jotform’s powerful online form features. View Available Plans
Jotform for Beginners.

Get more done with powerful, easy-to-use online forms.

Learn how in this helpful, free guide from Jotform.

Jotform for Beginners.
Download the Book