Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 7 Not Recognizing Twilio Client in Custom Module
    text
    copied!<p>I have a Twilio account and I am writing a mass text message module for my Drupal site. At the beginning of the module I have set up the Twilio client with the following code:</p> <pre><code>$path = drupal_get_path("library", "twilio"); require($path . "twilio/Services/Twilio.php"); $accountSID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $authToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $client = new Services_Twilio($accountSID, $authToken); $from = "xxxxxxxxxx"; </code></pre> <p>The myModule_submit() queries the database for phone numbers and sends them out via the Twilio PHP libraries referenced above. I am using code found on the Twilio site for something similar here(http://www.twilio.com/docs/howto/sms-notifications-and-alerts). The problem is when I fill in the forms for the SMS message to be sent out and press submit I get the following error message: </p> <p><strong>Notice: Undefined variable: client in myModule_submit() (line 128 of /var/www/erosas/anysite.com/sites/all/modules/myModule/myModule.module). Notice: Trying to get property of non-object in myModule_submit() (line 128 of /var/www/erosas/anysite.com/sites/all/modules/myModule/myModule.module). Notice: Trying to get property of non-object in myModule_submit() (line 128 of /var/www/erosas/anysite.com/sites/all/modules/myModule/myModule.module).</strong></p> <p>The submit function is:</p> <pre><code>function myModule_submit($form, &amp;$form_state){ // Retrieve the values from the fields of the custom form $values = $form_state['values']; // Use Database API to retrieve current posts. $query = db_select('field_data_field_phone_number', 'n'); $query-&gt;fields('n', array('field_phone_number_value')); // Place queried data into an array $phone_numbers = $query-&gt;execute(); $body = $values['sms_message']; // Iterate over array and send SMS foreach($phone_numbers as $number){ $client-&gt;account-&gt;sms_messages-&gt;create($from, $number, $body); // This is line 128 } </code></pre> <p>}</p> <p>Any thoughts/help would be greatly appreciated, I tried searching this site and Google for an answer, but nothing specific to Drupal came up.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload