0

I have this drupal site, there is a candidate registration page where anyone can fill the details (name, gender, address, mobile no etc) and submits and a success node page is displayed with all details applicant fills, then at admin side applications will be used for further offline processing. Everything is working fine.

What i am trying to do now is, after filling the details - like mobile number and other details applicant will click on submit button and all will be saved to database as usual but an sms will be sent to that mobile number.

I have my php sms script ready, but can't really add / embed it on form submission where i guess it will catch the mobile number and my php sms script will be run.

<?php
$mobile = '10 digit mobile number';
$entityID = 'xxxxxxxxxxxxxxx';
$uname = "xxxxx";
$pass = "xxxxxxxxx";
$senderID = 'xxxxxxx';
$destination = urldecode($mobile);
$smsContent = urlencode(addslashes($smsbody));

$URL = "https://smsgateway.in/link?username=$uname&pin=$pass&message=$smsContent&mnumber=$destination&signature=$senderID&dlt_entity_id=$entityID&dlt_template_id=$tmpltID";

if ($destination != 0) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, '/ca-bundle.crt');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (stristr($response, "info=Platform accepted")) {
   // $messageArray[] = $mob;
}
curl_close($ch);
}
?>
2
  • You need to provide more details so we can help you. Are you using the core Drupal contact form, or you're using the webform module? Basically, you can alter the form and submission by using HOOK_form_alter or HOOK_form_FORM_ID_alter to achieve this. More details can help us help you. Commented Feb 6, 2023 at 5:49
  • One of these: api.drupal.org/api/drupal/…
    – leymannx
    Commented Feb 6, 2023 at 7:43

1 Answer 1

0

You can use hook hook_ENTITY_TYPE_insert https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_ENTITY_TYPE_insert/8.4.x

You also can use hook_form_alter or hook_form_FORM_ID_alter and put the SMS script on that hook.

Note: Remember to restrict the send SMS on first time submit / or some conditions to avoid spam sms. Those hooks run on every submit though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.