Posting Flash Form values to Server Side

February 16, 2007

After trying for some half an hour I finally solved the problem of posting values from flash to PHP. I used LoadVars Object for this purpose. LoadVars object is used for transffering values between Flash and Server. It has various properties, methods and events which also helps in determining the successful data loading and communication between server.

In flash you can create LoadVars in following way

var loadVarObj = new LoadVars();
loadVarObj.firstName = “Vijay”;
loadVarObj.lastName = “Khambalkar”;
loadVarObj.skills = “PHP, ASP, Coldfusion, Flex, Javascript”;
loadVarObj.send(URL,loadVarObj,”POST”);

This is how your typical loadvars code will look like in case when you need to post values to server side. I found it interesting and thought to share.

One more thing I noticed about the loadVarObj documentation
public send(url:String, target:String, [method:String]) : Boolean

But this part didnt work, you need to event pass object itself as a second parameter. Only then your values is get posted. This is problem where I stuck initially.

Hope this much information will help you.


Making your application with dynamic debug options

February 12, 2007

Many times our client report that you had debug string into an application. This debug string could be printed array, values echo from database, database queries and many other things. Even in flex/javascript application client report that their are unnecessary alert that is coming in between. These are not actually a errors these are the development level debug messages which we mistaken unable to comment.

What is the solution to this common problem?

The day I realized that I can control this, I started using the concept. Thanks to my previous boss Kaushik Chatterjee who bring this forward for me. Concept is fairly very simple. Define a global level debug variable with default value 0. Following code will explain what I am trying to convince.

<script language=”javascript”>

var debug = 0;
function debugMessages(message)
{
if(debug)alert(message);
}
function getUserName()
{
debugMessages(“I am in this function”);
}
</script>

Above code is pretty simple to understand the concept.

First line of code defines debug variable with value 0 i.e 0 disable/ 1 enable

function debugMessages is responsible for all debugging messages. All messages will route through this function. Inside this its checking whats the value of debug variable. If its true then show alert message or simply discard it. So you can kept the value of debug variable always true as and when working on the development version. At production level simply turn off this variable and there will be no extra debug alert/message in the application.

Applying smart use of this technique, we can achieve alot and stop client from complaining these silly points which we really dont mean too. Atleast it will remove one bug from your system as entered by client as a bug.

🙂


Lets Appear on the blog Vijay

January 11, 2007

So finally I have snap of mine which I am posting on the blog here.
vijay-big.jpg


PHP Use of regular expression ereg_replace smartly

January 11, 2007

I was working on the application and came accross a situation where I need to replace all character except the numeric ones. My text pattern was something similar to varchar(20). I initial thought to use substr, later moved to explode using “(” token. I suddenly strike is ereg_replace can help me to do this. After writing one line of code I am happy it solve the purpose.

echo ereg_replace(“[a-zA-Z()]”,””,”varchar(20)”);

[a-zA-Z()] searches for all the occurences in the string and replace them with supplied character.

I very hardly uses ereg_replace but from now onwards I will encourage myself and others to use ereg_replace.


Something you can always do at database level

January 9, 2007

I found many developers even sometimes I do some code which could be possible at the database level. Why to format date at coding level when DATE_FORMAT function is available.

Developer should be careful enough to identify the cases where they can performes operation at database level. This will help to improve the overall performance and efficiency of your application.

I will be keep adding the tips about the same in this entry

First
=====
If you want to format date by fetching it from database, you can use DATE_FORMAT function.

eg. SELECT DATE_FORMAT(now(), ‘%y’) FROM tableName


My cute little Bhanja (nephew) Kaustubh

January 3, 2007

Its about 2 years back, I took my 1 year nephew to the nearest photo studio and ask them to take some random photograph. I get back to home with the soft copies of photos, imported them and edited in Photoshop. How its looking?. He is now 3 year old and started driving mini bicycle.


My cute little Bhanja (nephew) Kaustubh


Lessons learned

December 25, 2006

Last week I was not able to post any entry in my blog, lots of work was done last week. Code refactoring, javascript validators, Smarty templates formatting are some major areas I worked on.

There was too many good things I learned. Firstly I took javascript validation part for my project, I found there were so much redudant code I written when I started working on the project. After taking some deep grasp on it, I was able to implement new validation function which does most kind of validation for me. This was the great achievement from last week. I wrapped my 1000 lines of code within just 100 lines, I am feeling very good about this. I share the code with some other team members and they were happy about the approch I took.

Smarty was one more things which was looking very egly no proper identetion, formatting, comments. No uniformity within the codes. I clean up most of the smarty templates, there are still some more which I will clean up this week.

In PHP, I clean up most part of PHP script, I feel very sorry that I didnt concetrated initially on my code which leads to this.

Some notes I took from this incident
-Always write good code, think before writing the code.
-Analyse it in every aspect, how it can help you in future.
-Is your code is easy to modify in future.
-Can I use the same code in other projects too.

I already started implementing this earlier but not on this project, that was mistake from my side.

But finally I am happy that I clean up many things last week.

Cheers!!