designing4u.de Yet Another Coding Blog

29Jul/110

Conditional validation of shipping address using Zend sub forms

Zend Framework documentation gives you an excellent example on how to use sub forms. Sub forms let you split the logic of your application into smaller parts, validate it on demand and after collecting all the information validate the whole entity. Pretty cool huh? Lately I was implementing a shopping cart. In the last part of the check out process the user has to provide the billing address and shipping address. Usually they are the same but sometimes they differ. Here is how I solved the conditional validation of the form fields for orders where shipping address differs.

10May/090

Zip code search using jQuery and Google maps – displaying results in a defined radius

Last time I wrote about handling a Google map event, which is triggered, when a user moves around the map. I only mentioned that I had to use this solution for one of my projects, which goal was to display companies branches in a certain distance radius. I decided that it probably will be really interesting for all of you, how to display all company branches according to user input, therefore this time I will show you, how to retrieve the addresses of the places from a MySQL database, based on the zip code and radius provided by a user. I will also split this example in two parts. Todays part will only handle retrieving the results, displaying a simple navigation and markers on the map. In the second part we will push our project a little bit farther and we will allow our user to display the directions from the zip code he or she provided to the branch of his or hers choice.

11Nov/082

Google Maps and jQuery – calculating distance between two points

It has been a long time since I wrote my last example, but I've been really busy. Lately I got a request to write an example about calculating the distance between two points using KML file. What I will show you in this example is how to provide an user two drop down fields, which will be build according to provided KML file. Choosing each field will show a marker on the map. Changing the drop down field will cause removal of an according marker and placement of it in a new location. Also the markers will have two different colors, so an user can differentiate between starting and ending point. As the last functionality we will add a button. After an user clicks on the button, our function will calculate the rout and display the distance in kilometers. Let's start with a simple class which we will use to display drop down field and retrieve the coordination of requested place.

4Aug/0821

Google Maps, jQuery and XML – saving markers with user input

I just got a first request from a user of my site to help him with his problem. Let me describe it in detail. Assume that a user is visiting your site and he or she wants to place a marker on a google map displayed on your page. Additionally, we want to get some input from our user, therefore after he or she clicks on the google map we will provide an info could with a form. Our user will be able to provide a name, a message and a link and submit it. I didn't want to make this example too complicated, therefore handling the links or uploading the files you will have to solve by yourself. Let's move to the code.

19May/083

Class for retrieving region, city and geolocation

For one of the social platforms I was creating I had to provide profile display according to the location from which the request was made. There are plenty services in the internet, which provide you an accurate database, which will translate IP address into region, city and geographical lengths. I didn't want to spend any money for this kind of service, so I decided to find a free solution for this task. However, none of the services existing in the internet provides you 100% accuracy, the one that I've found locates my IP correctly. It would be nice, if you could give me some feedback, if this class is working for you as good as it works for me. This example requires URL file-access to be enabled on your server, because we will request the XML data through URL call. In this example we will also use SimpleXMLElement class, which should be enable by default in PHP5, to translate our XML file into an object. We will then recurse received object into a suitable array.

16May/080

User registration class – simple authorization of user

This days almost any site is providing the users a simple registration to provide certain services only for registered users. This way you can collect their e-mails and keep in touch with them. If you planing on developing a social platform or just web 2.0 project you need to authorize your users and ask them to provide a valid e-mail address. In this simple example I will show you, how you can do that using this simple class.

14May/080

Class for picture upload with fix width and height

For one of my web 2.0 projects I had to develop a solution for users to upload their images with fixed width and height. Basically my customer wanted to display profile images on the start page, but the requirement was to display each of them in a div container with fixed width and height. Because I'm not a CSS guru and I didn't want to set negative background position to display only parts of the images or because of the problems, which CSS has with different browsers, I came up with a solution, which does that pretty good. My class has a simple configuration and according to the width or height of an image uploaded by a user, resizes it to predefined width or height and places it according to the case vertically or horizontally in the center. This description might be confusing right now, but if you read this post to the end I hope you will know, what I meant.