2

Google Maps API and ColdFusion

While I was experimenting with Google API for my CA 288 ColdFusion class final project, I discovered that the ColdFusion variables can be used within the script tag. So I tried it out. I put the cfoutput tag outside the script tag in order to use the ColdFusion variables inside the script tag. And then I added cfif statement inside script tag to set the default latitude and longitude values to New York if there is no URL variables. Here is the cfelse part of the code:

var co_lat=#URL.a#;
var co_long=#URL.o#;
initialLocation = new google.maps.LatLng(co_lat,co_long);
var marker = new google.maps.Marker({
position: initialLocation,
map: map
});
contentString = “<br />#URL.d#:” + “<br />” + “Latitude: ” + co_lat + “<br />” + “Longitude: ” + co_long;
map.setCenter(initialLocation);
infowindow.setContent(contentString);
infowindow.setPosition(initialLocation);
infowindow.open(map);

I also used ColdFusion variables to convert them into the JavaScript variables as you can see on the first two lines of code. I also added a marker to the map to show the accurate location for the data provided. This is best used for creating maps from a list of places. For usage example, go to http://160.253.0.40/Students/Students/0111/browserGeo.cfm?d=Addo%20Entrance&a=-33.44431&o=25.73872. To download the source code, visit http://code.google.com/p/ca288-final-spring-2010-mc/downloads/list

0

PHP Form Validation Tip

While doing the assignment for my CA 282 PHP class today, I came up with a trick to minimize the amount of code that I need to write for the validation rule of each form element. This trick especially best used for validating forms with lots of form fields. The following is the PHP code:

if (isset($_GET['submitted'])) {
$field=”username,password,pwconfirm,fname,lname,address,city,state,zip,email”;
$fieldName=”User Name,Password,Confirm Password,First Name,Last Name,Home Address,City,State,Zip,Email”;
$field = split(“,”,$field);
$fieldNm=split(“,”,$fieldName);
for ($i=0;$i<10;$i++) {
if (empty($_POST[$field[$i]])) {
$errorMsg .= $fieldNm[$i].” is required.<br />”;
$success .= “False”;
}
else {
$success .= “True”;
}
}
if (!strstr($success,”False”)) {
$errorMsg=”The form successfully submitted.”;
}
}
else {
$errorMsg = “”;
}
echo “<div id=”noVal”>”.$errorMsg.”</div>”;

As you can see from the code above, I use split function to convert the combined form field names and the actual name for each form field to arrays. I then used a for loop to loop between form fields to validate the form. This is a simple form. It only checks all the form fields that left blank. You can use continue command inside the for loop for certain form fields that don’t need to be validated. You can also use email validation and password=password_confirm validation inside the for loop. Also note that the noVal id at the end of above code is just used to display the error massages to red color and bold.

1

Discovered a Bug in the Web Application

I encountered a small bug in my Computer Concepts web app while I was doing the assignment using the app. It seems to always output a forward slash in front of each single quote on the print layout table. Please refer to the following screenshot if you don’t know what I’m talking about.

Forward slash bug in the web aplicationForward slash bug. Click the image to enlarge

Thankfully, I found this post in the Dev Shed forum that provide a native PHP function to remove the forward slashes. I applied the function stripslashes($string) to the output value and the forward slashes are now gone.

Here is the updated source code for anyone who downloaded my last source code:

http://www.robbychen.com/cs110/worksheet_sourcecode.zip

If you find more problems while using the app, please leave a comment. I will fix it as soon as possible. Thanks.

0

Computer Concepts Assignment Aid Web App released

I finally completed the project and will be released under CS 110 homepage over robbychen.com soon. The following are some features of the web application (NOTE: This application is primarily made to help me to finish the assignments easier. However, anyone can use it if it helps to make life easier. This web app doesn’t contain any database-related function nor server/client log script, so you can safe to use it):

  • Each text field is auto expandable thanks to the autoResize jQuery plug-in.

Each text field will automatically expand once text in the text field reached the bottom of the text field.

  • The ability to add more rows using PHP.

The default number of rows is 20. Once you reached the last row at the bottom of the page, the Add a New Row button will appear. NOTE: this button will disappear if I don’t enter anything to any three of the text fields, it assumes that I had completed entering the data. After clicking the button, the page will refresh and it will scroll to the bottom of the page to letting me to enter data in the new row. I use the scrollTo jQuery plug-in to achieve this effect.

  • The option to print out the completed sheet after clicking the Submit button.

Once I clicked the Submit button, two buttons will appear on both top and bottom of the page, print button and edit button. It allows me to print out the completed sheet in order to hand in to the professor. The buttons on the page will not print out with the assignment sheet. I specified the print style sheet to hide the buttons while printing.

  • The option to edit the fields after it was submitted by clicking the Edit button.

The Edit button is simply using history.back() Javascript function to go back one page. I have not think of a way to achieve this without using database or session variables yet since my goal is to not leave any trace of the application on the computer and on the server.

Here is the side-to-side comparison between the original (non-digitized) version of the assignment sheet and digitized one:

Comparison between origial version and digitized versionComparison between original and digitized version. Click the image to enlarge

The following is the URL for this web app if you want to go to it directly:

http://www.robbychen.com/cs110/worksheet/

0

Changing Plan

I just found out this morning school is open today despite that today is President’s Day in the US. I have to postpone my project to Wednesday since I don’t have access to a scanner to scan the original assignment sheet. Right now I’m completing assignment for Computer Concepts class. I know the web app for helping me to complete this assignment is not finished yet. Since this assignment is due tomorrow, I have to complete this by hand. Besides, if I finished building the web app, I don’t have access to a printer to print out the assignment, and I have classes until ten o’clock on both evenings today and tomorrow.

So I decided to delay my web app “release” to Wednesday. Today I’ll complete my Computer Concepts assignment. The completion of the web app will be tomorrow. On Wednesday, I will scan the original assignment sheet to my laptop, compare between the web app and the original, and upload the project. As I wrote on previous post, it will be uploaded under the CS 110 homepage on robbychen.com website.

0

Dream Recorded from This Morning

NOTE: This is my PY 102 (General Psychology) course assignment. It’s completely unrelated to the Open Source topic.

I rarely dream about something. When the professor assigned us a Dream Log Analysis project during the first General Psychology class, I immediately thought that I could not complete this project since I haven’t had any dreams for a long time. Luckily, I had a dream this morning and recorded most of my dream after I woke up. Here is most of the story in my dream:

When I woke up in the morning while it’s still dark outside, my parents were gone. I saw lots of keys on the table and somebody was cooking 3 big bowls of breakfast. Then I discovered that the front door was opened slightly. I opened door and shouted out “anyone there?” I found out that I forgot to put my keys away after I opened door last night. I immediately remove my keys from the door and locked the door. Then the voice of an old man shouted and knock very hard in front of the door. I got scared. At last moment, I woke up from my dream by the alarm clock.

Here is my analysis:

I dreamed this event probably because I sometimes forgot to put away my keys after I unlocked door when I got home. I often remember my keys the next morning. If we live in a worse community, this dream could come true. Another probable cause is that my parents will out of country for 10 days in March. At that time, it will only have myself in the home. This reminds me to always secure the house whenever I’m in and out of the house.