This text is replaced by the Flash movie.

Archive for the ‘Coding/Programming’ Category

keytool and Android Maps

May 20th, 2011
Using Maps on Android is quite hard to implement compare to Apple's iPhone and xcode development, it's really weird that Google have to make these troubles for their Android developers. You have to generate API key before you can use the map or else you are just gonna see tiles.

Map With iPhone Xcode(Objective-C) is simple to implement.
Android Maps

Map With Android Eclipse(Java) Not following instructions from Google Site will just show tiles.
Android Maps

Before you can generate API key for your android applications with map in it. You have to go http://code.google.com/android/maps-api-signup.html and follow the steps, on windows I found out that the keytool is not recognized. keytool is one of Java tools,

Android Map

so the simple fix was just I browse down to my Java bin folder L:\Program Files\Java\jre1.6.0_07\bin and check if I have it there, then add it on the Environment Variables PATH, to make it easy for you to call this executable file while you are in the current folder of debug.keystore.

Android Map

So After Obtaining API Key I finally can see the Map on Emulator powered by Google Apis.
Android Maps Android Maps

PhoneGap Copy Javascript Error

May 16th, 2011
I'm trying something new right now, web apps on smartphones, while trying to shell a simple html I did, (just displaying a JS alert box) I got this error that phoneGap can't transfer something.

PhoneGap JS Debug

The simple fixed was just rename the folder that has space on it going to your xcode project.

PhoneGap JS Test

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'....


Zend Framework Library 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.

Transition Between 2 Movie Clips with Tween Class

February 18th, 2011
This is just Basic Flash ActionScripting with 2.0 Using TweenClass Between 2 movieClips. In this example I used 2 images which converted to were movie clip, which I will make first Movie Clip to appear first by transitioning from alpha 0 to 100 then transisioning back from 100 to 0 and then calling Movie Clip 2 to do the same transition then loop back to Movie Clip 1 to repeat the transition.

First Have your first movie clip then convert it - name it anything you want.

Converting to a movie Clip

The important part is assigning the instance name of the movie clip, this is the ActionScript name going to identify. For this example I name firt movie clip as movP1 and second movie clipt as movP2.

Instance naming movie Clip

so put this as2 script inside a frame (where the movies are also visible)

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
import mx.transitions.Tween;
import mx.transitions.easing.*;
 
movP1._alpha = 0;
movP2._alpha = 0;
 
firstTween();
 
function firstTween(){
var Tween1:Tween = new Tween(movP1, "_alpha", Strong.easeOut, 0, 100, 5, true);
setTimeout(doNextTween, 5000);
 
}
 
function doNextTween(){
  var Tween2:Tween = new Tween(movP1, "_alpha", Strong.easeOut, 100, 0, 5, true);
  var Tween3:Tween = new Tween(movP2, "_alpha", Strong.easeOut, 0, 100, 5, true);
  setTimeout(loopBack, 5000);
 
}
 
function loopBack(){
  var Tween4:Tween = new Tween(movP2, "_alpha", Strong.easeOut, 100, 0, 5, true);
  setTimeout(firstTween, 100);
}


setTimeout(doNextTween, 5000);
this call the function after 5 seconds.

Demo:
Flash required


Or Just
Download The Source File.

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); ?>
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.
 ?>