Hi
Im using CCK and CCK button and I need some advice.
Im using the CCK button programmed with the following php code which sends an SMS message. It works fine but I want one of the variables $selectednums to use the value of another cck field on the form $bookings->field_mobnum. How can I do this?
Heres the code:
$info = "1";
$test = "0";
$address = "www.txtlocal.com/sendsmspost.php";
$message = "DISPATCH CONFIRMATION, ANY QUERIES CALL US ON 0208 577 7713";
$from = "EE";
$uname = "username";
$pword = "password";
$selectednums = "079XXXXXXX";
$newSMS = new sms;
$newSMS->smsCurl($address, $uname, $pword, $message, $from, $selectednums, $info, $test); // Sends an SMS using cURL
$newSMS->smsSockets($address, $uname, $pword, $message, $from, $selectednums, $info, $test); // Sends an SMS using sockets
class sms {
// cURL SMS
function smsCurl($address, $uname, $pword, $message, $from, $selectednums, $info, $test=0)
{
// Build url
$data = "uname=" . $uname . "&pword=" . $pword . "&message=" . urlencode($message) . "&from=" . $from . "&selectednums=" . $selectednums . "&info=" . $info . "&test=" . $test;
// Initiate cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://$address");
// curl_setopt($ch, CURLOPT_URL,"https://$address"); //secure connection
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //use this to suppress output
$result = curl_exec ($ch); //This is the result from Txtlocal - store as required
curl_close ($ch);
}
// Socket SMS
function smsSockets($address, $uname, $pword, $message, $from, $selectednums, $info, $test = 0)
{
// Build data array
$data = array ("uname" => $uname, "pword" => $pword, "message" => $message, "from" => $from, "selectednums" => $selectednums, "info" => $info, "test" => $test);
$data = http_build_query($data);
do_post_request("https://www.txtlocal.com/sendsmspost.php", $data);
$params = array('http' => array('method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($address, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
}
Thanks in advance
Alex
Comments
Not sure exactly what your
Not sure exactly what your question is, nor where this code is, but you may need to use node_load to load the node in question into a variable. Use print_r then to see what's there and see if the field you need is available that way, as in:
$node = node_load($x); // where $x is the id of the node
HTH
Thanks HTH
OK - Ive created a custom content type called bookings. Within it are various fields, one of them is field_mobnum to hold mobile numbers. The custom form also has a CCK button with the code (as in the previous message) to send an sms.
I want the variable &selectednum in the code to equal the value entered in the field_mobnum cck field and not just hold a static number i.e.
&selectednum = $bookings->field_mobnum[0]['value'] (Doesnt work)
Hope that explains it