Score:0

Run custom php code or file in drupal content type form submission

cn flag

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);
}
?>
Hodba Khalaf avatar
eg flag
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.
leymannx avatar
ne flag
One of these: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/group/entity_crud/9.3.x
Score:0
sa flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.