Archive for the ‘PHP’ Category
Two Versions Cake Console
January 13th, 2012
Cake 2.0 was recently release, but I don't want to migrate yet some applications I already build with this version (afraid there are so many changes) most of my work are under 1.3, so I just decided to study it first. To have 2 cake console what I did is just to add another path in environment variables, Cake 2.0 console path is at cakephp/app/console and just rename cake.bat to cake2.bat, now I can use 2 cake versions within my current PC system.
ZendFramework Library
March 1st, 2011
if somehow you encounter this kind of error(mostly this will be encounter by first timers using ZendFramework)
Warning: require_once(Zend/Application.php) [function.require-once]: failed to open stream: No such file or directory...
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Application.php'....
you can either include the path library(where you installed Zend Framework your client path) in your php.ini,
or manually copy the zend library under your application library folder.
for php.ini settings
where /usr/local/ZendFrameworkCli is the path I installed my ZendFramework .../library is where the zend libraries are located.
Warning: require_once(Zend/Application.php) [function.require-once]: failed to open stream: No such file or directory...
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Application.php'....
you can either include the path library(where you installed Zend Framework your client path) in your php.ini,
or manually copy the zend library under your application library folder. for php.ini settings
include_path = ".:/Applications/MAMP/bin/php5/lib/php:/usr/local/ZendFrameworkCli/library"
where /usr/local/ZendFrameworkCli is the path I installed my ZendFramework .../library is where the zend libraries are located.
SF forms with captcha
January 27th, 2011
Adding captcha with web-to-lead forms
There are times you want to avoid those annoying bots filling your forms and putting garbage into your data with in your salesforce leads, there are measures to avoid this and if you prefer using captcha, you might want to use reCaptcha. If you know how to code with salesforce apex this link will already solve your problem. But for those who prefer using the simple web-to-lead form you can use CURL with PHP to reprocess the data being submitted and submit it to salesforce. In this example I'm using PHP with cURL and ReCaptcha. This is just basic PHP coding.
The Basic Form
First is the sf form created by Web-to-Lead on App Setup and editing some parts
In action form https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8 change this to the php page you want to reprocess the data
Some of the fields I used are custom fields for some reason salesforce generate name with number at the beginning which will cause a lot of trouble with javascript and php when trying to use it with in your code.
So you need also to rename some input datafield with name has number at the beginning, in this case 00N40000001oHG5 I change it to From_Link and 00N40000001pyzT for Region
Add the recaptcha field at the end of your form before submit.
<? echo recaptcha_get_html($publickey); ?>
Applying the reCaptcha - STOP SPAM READ BOOKS(Seriously Spammers!)
Now After submitting the form it will check first if the captcha is right. You may need to put the code below - at the head of your php page where the data will be process first, or you might want to read this first on how to use reCaptcha with PHP http://code.google.com/apis/recaptcha/docs/php.html
Appying cURL
Now appying Using cURL, to be able to do this - your server should be running cURL library, taking the idea from David Walsh on how to post via cURL method http://davidwalsh.name/execute-http-post-php-curl, notice on $fields array I used the field name 00N40000001oHG5 for $From_link and 00N40000001pyzT for $Region, so once the data are being submitted it will check first in this sample php code before submitting it to salesforce's site.
So here is the full listing for submission to salesforce site.
There are times you want to avoid those annoying bots filling your forms and putting garbage into your data with in your salesforce leads, there are measures to avoid this and if you prefer using captcha, you might want to use reCaptcha. If you know how to code with salesforce apex this link will already solve your problem. But for those who prefer using the simple web-to-lead form you can use CURL with PHP to reprocess the data being submitted and submit it to salesforce. In this example I'm using PHP with cURL and ReCaptcha. This is just basic PHP coding.
The Basic Form
First is the sf form created by Web-to-Lead on App Setup and editing some parts
In action form https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8 change this to the php page you want to reprocess the data
Some of the fields I used are custom fields for some reason salesforce generate name with number at the beginning which will cause a lot of trouble with javascript and php when trying to use it with in your code.
So you need also to rename some input datafield with name has number at the beginning, in this case 00N40000001oHG5 I change it to From_Link and 00N40000001pyzT for Region
Add the recaptcha field at the end of your form before submit.
<? echo recaptcha_get_html($publickey); ?>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <form action="check-this-first.php" method="post" name="emailForm" id="test" style="padding: 0px; margin: 0px;" > <input type=hidden name="oid" value="00D40000000IUAQ"> <input type=hidden id="From_Link" maxlength="255" name="From_Link" value="<?=$cameFrom ?>" /> <!-- came from link //--> <input type=hidden id="Campaign_ID" name="Campaign_ID" value="701400000005waD"> <!-- Google Ad Words //--> <input type=hidden id="recordType" name="recordType" value="0124000000014Ed"> <!-- Google Ad Words //--> <input type=hidden name="retURL" value="http://www.thankyoupage.com/merci-beaucoup"> <table> <tr> <td >First Name: <br /> <input style="width:200px;" id="first_name" maxlength="40" name="first_name" size="20" type="text"/> </td> </tr> <tr> <td >Last Name: <br /> <input style="width:200px;" id="last_name" maxlength="80" name="last_name" size="20" type="text" /> </td> </tr> <tr> <td >Email:<br /> <input style="width:200px;" id="email" maxlength="80" name="email" size="20" type="text" /></td> </tr> <tr> <td >Company:<br /> <input style="width:200px;" id="company" maxlength="40" name="company" size="20" type="text" /> </td> </tr> <tr> <td >Country: <br /> <input style="width:200px;" id="country" maxlength="40" name="country" size="20" type="text" /> </td> </tr> <tr> <td >Region: <br /> <select id="Region" name="Region" title="Region"><option value="North America">North America</option> <option value="South America">South America</option> <option value="EMEA">EMEA</option> <option value="APAC">APAC</option> </select></td> </tr> <tr> <td align="left" > <span class="style1 style2">Verify Code:<br /> <br /> <!-- Captcha//--> <? echo recaptcha_get_html($publickey); ?> <!-- Captcha //--></td> </tr> <tr> <td> <br /><br /> <input type="submit" name="submit"> </td> </tr> </table> </form> |
Applying the reCaptcha - STOP SPAM READ BOOKS(Seriously Spammers!)
Now After submitting the form it will check first if the captcha is right. You may need to put the code below - at the head of your php page where the data will be process first, or you might want to read this first on how to use reCaptcha with PHP http://code.google.com/apis/recaptcha/docs/php.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <? ob_start(); session_start(); include_once('recaptcha/recaptchalib.php'); //Recaptcha Settings $publickey = "xxxx"; // you got this from the signup page $privatekey = "xxxx"; extract($_POST); if ($submit){ //if its sumbitted $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); $ok = 1; if (!$resp->is_valid) { //if captcha is invalid $ok = 0; } if ($ok){ //Put here the data for sf leads storing } else { // Message here that the captcha was invalid } } ?> |
Appying cURL
Now appying Using cURL, to be able to do this - your server should be running cURL library, taking the idea from David Walsh on how to post via cURL method http://davidwalsh.name/execute-http-post-php-curl, notice on $fields array I used the field name 00N40000001oHG5 for $From_link and 00N40000001pyzT for $Region, so once the data are being submitted it will check first in this sample php code before submitting it to salesforce's site.
So here is the full listing for submission to salesforce site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <? ob_start(); session_start(); include_once('recaptcha/recaptchalib.php'); //Recaptcha Settings $publickey = "xxxx"; // you got this from the signup page $privatekey = "xxxx"; //curl method posting //extract data from the post extract($_POST); if ($submit){ $ok = 1; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $ok = 0; } if ($ok){ //set POST variables $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8'; $fields = array( 'oid'=>urlencode($oid), 'Campaign_ID'=>urlencode($Campaign_ID), '00N40000001oHG5'=>urlencode($From_Link), 'recordType'=>urlencode($recordType), 'retURL'=>urlencode($retURL), 'first_name'=>urlencode($first_name), 'last_name'=>urlencode($last_name), 'email'=>urlencode($email), 'company'=>urlencode($company), '00N40000001pyzT'=>urlencode($Region) ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //print_r($fields_string); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); } //if ok else { echo "<h4>Sorry - Invalid Captcha </h4>"; } } //if submit. ?> |
ZendFramework PublicPath
December 10th, 2010
Solution - in this forum http://stackoverflow.com/questions/2003101/zend-and-htaccess
So I won't forget how to fix this. when I encounter the problem again
So I won't forget how to fix this. when I encounter the problem again
Joomla 1.5 Article Trash
December 4th, 2010
While debugging the component I created I noticed that the query was returning some articles I didn't knew existed. I found out that these articles are just trashed.
The simple way to separate article trash from active articles is to get the state datafield of the table #__content equals to 1.
Where in this query . "\n WHERE ( a.state = 1 )" should do it.
The simple way to separate article trash from active articles is to get the state datafield of the table #__content equals to 1.
1 2 3 4 5 6 7 8 9 10 11 | $query = "SELECT a.*, n.*, t.*, n.link as linkThisPage" . "\n FROM #__componentnews_news AS n" . "\n LEFT JOIN #__content AS a ON a.id = n.pr_id" . "\n LEFT JOIN #__componentnews_types AS t ON t.id = n.type_id" . "\n WHERE ( a.state = 1 )" . "\n AND ( a.publish_up = " .$database->Quote($nullDate) . " OR a.publish_up <= " . $database->Quote($now) . ")" . "\n AND ( a.publish_down = " . $database->Quote($nullDate) . " OR a.publish_down >= " . $database->Quote($now) . " )" . "\n ORDER BY $orderby" . "\n limit $skip," . $count; |
Where in this query . "\n WHERE ( a.state = 1 )" should do it.