Showing posts with label zencity. Show all posts
Showing posts with label zencity. Show all posts

Wednesday, 4 June 2008

Object-oriented form rendering using PHP, part 1

Well, hi again.

I have had to major annoyances these past two weeks:
- clearing my flat (those who know me well, know this is a endless task);
- and studying for a Dutch exam, which is today! So, there is lots of touching wood going on around here.

[UPDATE: the exam wasn't that difficult. I think I have made it to the next module. Actual results next Wednesday!]

The good news is I actually found my IT diploma certificate!

Other than that, I have continued my personal website, and also started working on anxcity, which I have already renamed zencity because we really want to focus on the aim rather than the "problem".

I know I shall be needing quite a few forms (especially for administration), so I have started developing a form publisher using object oriented PHP. The form and input nodes are ready, but I hope to be adding client-side and server-side rules shortly.

The general idea is (I haven't checked syntax so bare with me):

$form=new Form();
$name=new Text('name',40); // 40 is the size
$comment=new TextArea('comment',4,5);
$form->add($name);
$form->add($comment);
$form->display();


And of course ultimately:

// in the HTML head or before
$form=new Form();
$name=new Text('name',40); // 40 is the size
$name->addPreSubmitJS('trim');
$name->addOnSubmitJS('min-length',0);
$comment=new TextArea('comment',4,5);
$comment->addPreSubmitJS('trim');
$comment->addOnSubmitJS('min-length',0);
...
...
$form->add($name);
$form->add($comment);

// in the HTML head
$form->displayJS();

// in the HTML body
$form->display();

// once the form is actually submitted to server,
// apply server side rules



There are thus to separate types of rules:
- JS client-side rules (the usual: trim(), length()>0, etc.) that get tested before the HTTP request actually gets (or doesn't get) sent.
- PHP server-side rules (non-duplicate identifier, etc.) tested on the server-side once the HTTP request gets through.

Anyhow, once the personal website is up I shall be able to share more with you about the evolution of the project.

Any thoughts for now?
Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory