- First windows 7 and then Pivot ( http://www.getpivot.com ). Microsoft's starting to impress me! #fb #
- Feeling as if I'm doing less than half of what I could be. #fail #
- My new twitter background is a hint of what my site will look like. #
- Rammstein at full volume with headphones that handle bass well. \m/ #
- I've started typing Tryst when I want to go to Twitter; Foodiebay when I want to go to Facebook. This is getting scary. #
Powered by Twitter Tools
- #awesomeindianthings : awesomeindianthings is trending at #1 on twitter worldwide! #
- Drupal 7: First, basic impressions: the admin bar is excellent. Much better admin UI than Drupal 6! #
- Attended a twitter talk today: highlights - met one of the 140 @pankaj - learnt about @twi - & twitter's reliance on 3rd party apps. #
- She will be loved / Maroon 5 seems to have become one of my favourite songs. #
Powered by Twitter Tools
- Deciding how much information I want to/can process in a single day is painful. #
- #1 Complete foodiebay user preferences, clean up facebook and add email. #
- So how many people get to breakfast on a Turkey & Chicken Ham Sub followed by Cold Coffee and a Donut?
#
Powered by Twitter Tools
This is my second post in a series of 52 (yes, yes I've delayed a lot but I would prefer later, better posts than useless, on-time posts).
Forms are something that I end up coding on almost every website I make (without using a CMS, that is). Essentially, while making a form I have to:
- Write HTML code for the forms giving appropriate names and ids.
- Write PHP code that reads in these names from POST or GET and then filter them.
- Create appropriate error messages in PHP based on incorrect data provided in forms, and repopulate correctly filled fields in the form for the sanity of users.
- Write Javascript (or use a plugin from jQuery) to validate the fields inline using the exact same rules and show messages to users before submitting the form.
- Debug because I missed a character or capitalized something I shouldn't have.
- And then I realize I missed something, and then repeat.
This is also known as web developer hell. Somewhere near the inner circles.
Ideally, what would I want to do to get a form ready?
Specify what I want at one single place with some convenient format (— did anyone say JSON?)
So essentially, this post covers:
- Specifying a (modifiable) JSON format for forms.
- Generating HTML using PHP for those forms.
- Generating rules in PHP using this format.
- Generating javascript for validation using this format.
Building the specification:
Call it a whim or a fancy — I want to use JSON for my specifications. I cannot think of any other more convenient format for specifying data to be used in PHP and Javascript.
Let's take a look at all available form elements:
- input tags:
- button
- checkbox
- file
- hidden
- image
- password
- radio
- reset
- text
- submit
I'll only be taking a look at the types highlighted in bold text.
- textarea
- select
- option
- optgroup
- button
The specification as it is now
[{
'name' : '[form-name]' //Name and id of the form to be created.
'class' : '[ '[class1]', ... ]'
}, ...]
What do I need to specify for the form?
- The form structure — the JSON spec must follow the structure that the form will take. Specifying a contents array seems to be the best possible solution to that, allowing and defining fieldsets for forms nested inside forms.
[{ 'name' : '[form-name]', 'contents' : [ { 'name' : '[fieldset-name]', 'legend' : '[fieldset-legend]', 'class' : '[ '[class1]', ... ]' 'contents' : [ ... ] } ] }, ...] - So now we get down to the meaty part. Defining elements. Each element is an object with a type, name, label, an array each for attributes and classes, and an array for validation data.
[{ 'name' : '[form-name]', 'caption' : '[form-caption]', 'class' : '[ '[class1]', ... ]' 'contents' : [ { 'name' : '[fieldset-name]', 'legend' : '[fieldset-legend]', 'contents' : [ { 'type' : 'input-text', 'name' : '[name and id of the object]', 'label': '[its label. duh.]', 'attr' : [ '[attr-name]' : '[value]' , ... ], 'class': [ '[class1]', '[class2]' ], 'rules': [ ... ] } ] } ] }, ...]
To be continued.
Back to Basics: Forms
- Making my version of facebook's fanbox -- the difference? This one points to profiles on MY site and has users from FB, GFC & normal reg.
# - Oops -- the previous post was not supposed to have an @ anywhere. Note to self: careful what you tweet from docky. (eg. filenames!) #
- The tryst website crosses 500 registered users with 6,399 visits by 4,120 unique visitors from all over india. 31,403 hits! #win #firstmonth #
- Never knew adobe reader for linux had tabs. Does the latest win veri version have tabs too? #
Powered by Twitter Tools
- After manipulating js from one side of the browser for so long -- finally looking at it from the other side -- the javascript engine. #
- Creating user profiles. My work for the Tryst website seems to have become like a mini social networking site -- profiles, games, connects. #
- Been coding for too many days and hours now. Feeling tired. Will have to postpone user team registration and game for a 1-2 days, maybe. #
- Tryst 2010: 3268 lines of php, 171 lines of js, 777 lines of css. And counting. Whew! #
- Tryst 2010: 3268 lines of php, 171 lines of js, 777 lines of css. And counting. #tryst2010 #fb #
- iPad. Drool. http://www.apple.com/ipad/ #
- Wish I could line up all people who both waste my time AND bore me against a wall and have them shot. Not necessarily fatally. #
- Shifted to my new room! Single again, finally. #
- My faking news-ish post http://kunal-b.in/index.php/2010/01/hostel-collapses is spreading throughout facebook! Nice to see! #
- ~150 visitors on my blog today! Nice. (= 2 * EDC hits and .5 * Tryst hits) #
Powered by Twitter Tools
30/01/2010 The Windy Hostel, Indian Institute of Consultancy, Delhi: At 11.05 a.m. today morning a horrifying accident occurred because of gross negligence by engineers at Windy Hostel, IICd. The hostel had been undergoing renovation for over a year and work had recently started on a new block today. Students were still residing in the 4-story hostel on the top 2 floors while the bottom floors had been vacated.
In order to complete his work on time, the contractor had allegedly told the workers to demolish the lower portion of the building and start renovation work on it, without considering whether the already considerably weakened, 40 year old structure could take the weight. The inevitable occurred, with the top two floors crashing down and burying and damaging many laptops.
In the words of one of the surviving students (who has requested to remain unnamed) "They were destroying the doors beneath our room and the balcony start moving wildly, deflecting as much as 1 cm. We ran to stop them, but the [expletive deleted] workers refused to budge."
The maintenance secretary of the hostel was allegedly gallivanting somewhere in East Delhi during the incident, meeting some foreigner. On being contacted he replied that he had an urgent meeting with someone he could not name -- a fact that has been noted by the investigating authorities who have taken him into custody. We managed to get a statement from the Chief Investigator, Mr. M. Adi "We have not ruled out the involvement of the maintenance secretary, and are also considering the foreign angle", obliquely referring to the recent statement by the President of United States of Pakerica, Mr. Obama Bin Bush.
Being a holiday, most of the students were sitting in their rooms during the accident, apparently trying to block their internet access so as to be able to prepare for their upcoming examinations. A quote by one of the IICians from our archives: "Our professors believe that we can obtain everything we need to learn by surfing the internet -- in fact they maintain a check to see that all students download at least 100MB of data every day to ensure they are spending enough time on the internet. We have learnt a lot but it becomes difficult to adhere to this rule during our minor exams so trying to outsmart our professors and blocking our internet access is a favourite pass-time for IICians during the exam season."
Most of the students were taken by surprise as the building came crashing down on them, and more than 50 laptops have been reported missing and are assumed to still be buried under the rubble, while 10 damaged (2 critically) laptops have been recovered. One or 2 lucky laptops survived on their battery life and were discovered as they were playing heavy rock and could be heard through the concrete. Worried students at IIC have kept a candle light vigil outside the laptop repair shop, with the very best technicians of the top laptop manufacturers including Nosy Baio, Sell and Compact working tirelessly to save the laptops. More technicians are expected to arrive from around the world soon. Excavation work to locate the remaining laptops is also underway.
Many IICians are still in shock, with many roaming around in a daze. A particularly sad case is that of a few students, who, being deprived of access to their laptops and the Facebook live feed appear to have devolved to animals -- with one imitating a bull, another squealing in French like a pig and the worst affected keeps trying to fly off the top of the hostel and is constantly restrained by his friends. It is currently not clear whether he has delusions about being a bird or being the Man of Steel (both being able to fly).
What has made this accident even more unique is the fact that there have been various reports of the accident being a complete fabrication and fallacy as people have allegedly communicated with the missing residents of the hostel (using their own laptops). In the public interest, we reiterate that the accident has happened and any such rumours must be disregarded as utter nonsense.
There have been suspicions of paranormal activity at the site of the accident because of these apparent messages and the top investigative news channel in India -- IndiaTV -- has sent its best reporter to find out the truth. The initial findings of the reporter will be presented on tomorrow's primetime show at 8 p.m. -- "IIC ke khooni engineer". Insiders (who wish to remain unnamed) have said that such a tragic parting of nerds with their computers can cause their ghosts to linger on till they manage to complete their last wish: to update their status messages. Only then will they be able to pass on to the afterlife. As always, there are many skeptics who have denounced this theory, claiming that the ghosts need to play one last LAN game of AoE.
In a surprise turn of events, famed teen impersonator and actor Aamir K. and ex-IICian and MBA B. Chetan came together in support of the missing laptops. They said that they has put aside all differences to be able to garner even more publicity for their film/book as people had stopped discussing their recent disagreements.
- Tryst Iteration 2 is up! http://tryst2010.in . And my framework is progressing along nicely! #
- NERDTree and bufExplorer: 2 plugins for VIM I don't know how I survived without! #I<heart>gVIM #
- http://twitpic.com/ze66s - Split screen madness! #
- via @apnerve Excellent reading material: http://www.designingsocialinterfaces.com/patterns.wiki/index.php?title=Main_Page #
- Hopefully the last major change for the Tryst website tonight and then I move on to other pending work. #
Powered by Twitter Tools
- Adding stuff to tryst. Event details, facebook connect atm. Loads to polish and do. #
- Tip for those refreshing after a facebook connect logout to clean up server -- trigger the button after the callback from fb returns. #
- Finally achieved a degree of comfort with integrating Facebook Connect. It took me a long time! #
- Solitude: something you can achieve in space, or time. #
- This Years Biggest Mistake: eating a pizza from Pizza Square.
Never Again! #
- Problem with switching back to windows after using linux for so many days? Now I keep searching for "options" in the edit menu. #
Powered by Twitter Tools
- Using 9 workspaces. Started with 5, moved to 3 -- found myself wanting more -- switched to 9. Let's see how this works. #
- Finally got my reliance ZTE modem working on linux! I don't even want to _think_ about the hours and days I've wasted trying to do this! #
Powered by Twitter Tools

Recent Comments