PHP

Posts Tagged PHP

JavaScript chained select with MooTools 1.2

Friday, January 23rd, 2009 in Mootools, PHP | 17 comments

MooTools chained select ChainedSelect is a MooTools 1.2 JavaScript plugin that enables the user to navigate through parent – children tree structure with indefinite number of nodes and make a selection when the desired option is encountered.

This approach offers a more powerful solution versus the classical drop down boxes chained together for a number of reasons: it takes significantly less space in the page; it can contain any number of nested levels, navigation would not be harmed; it can be styled according to the overall page design from CSS and most of all, it looks better.

The purpose of the plugin is to replace the classic chained dropdown lists that have 2 or more selects and get populated with options once you select an option from a previous one.

The whole idea behind this plugin evolves around the tree structure generated by a file and sent to JavaScript as a JSON string. Giving the fact that the whole structure of the tree is loaded, the request to the script is made only once and then the response is reused when navigating the nodes. Once a node is selected, the plugin allows the user to return on the path he used to get to the current node.

If an option is selected and the script that verifies the user’s entry returns an error (for example the e-mail address is invalid), the plugin offers the possibility to display the last selected option leaving it selected and accessible in POST / GET depending what method you used on the form. (more…)

Tags: , ,

Write more compact php code

Thursday, July 10th, 2008 in PHP | 4 comments

I’ve been programming using and MySQL for about 4 years by now. One thing that I’ve always hated was to write code. Don’t get me wrong, I love coding, what I hate is writing in 10 lines what I could do in 5. Besides the fact that is a terrible waste of time and effort, when I was put in the position of revising the code at a later time (to make changes or just for the sake of improving the code) I found myself in trouble trying to understand what the hell I was thinking back then. Another scenario is when someone else is taking what you started ( I know this because I had to take on someone else’s projects ).

Giving this, why not spend a little time thinking first and then start coding? Below are a few things I’ve found out with time. (more…)

Tags: , , ,

Simple PHP math captcha image

Friday, June 22nd, 2007 in PHP | 28 comments

math captcha image There are tons of captcha scripts on the web. The problem is that, from the enthusiasm of making them more flexible, a lot of code and pages are added and instead of a simple solution one may end up with several files necessary to display the captcha image. I’m not saying that they are useless, but for most of the time, such complexity is not quite welcomed. I strongly believe that less is more and that things should be kept simple. Having that in mind, I want to share a way to protect your forms using a math captcha image that requires a single file and a font file.

This is a very simple, easy to understand example that shows you how to display a math captcha image that requires the user to do a little thinking. Simple operation like subtraction or addition is displayed on the math captcha and the user needs to input the result. Math captcha result is stored in session and from the page doing the form validation you just need to compare the value from session with the value that the user inputed. (more…)

Tags: ,