[PHP] Re: Forms validation and creation- easier solution?

2009-05-23 Thread Tony Marston

Daniele Grillenzoni dani...@b2informatica.it wrote in message 
news:16.1e.28112.84ca5...@pb1.pair.com...
 On 20/05/2009 9.03, Angelo Zanetti wrote:
 Hi all.



 We have done quite a few projects and we are looking to find better ways 
 to
 implementing forms.



 Forms seem to be quite time consuming and repetitive.



 Generally are there any classes or libraries that will assist with:



 1. Easy creation of forms (fields and layout)

 2. Validation of specific fields within the forms (server side not JS)

 3. Decrease in time required to setup the forms pages

 any other comments are welcome.



 Thanks in advance

 Angelo


 Elemental
 http://www.elemental.co.zahttp://www.elemental.co.za/

 Dynamic Web and Mobile Solutions







 Personally I created a little Class that handles it.

 First I create an array of associative arrays, every associative array 
 represents an input of an abstract type (similar to the webforms, meaning 
 i have stuff like type=telephone).

 Stuff like
 $inputs[]=array(
 name = foobar,
 required = true,
 type = string,   // text is reserved to textarea
 label = Foo Bar,
 error_required = you need to provide a Foo Bar value, dummy,
 group = main
 );
 etc.

 Then I create an array for groups.
 $group[main] = array(
 type = block, // types are either block which means div, set which 
 means fieldset, paragraph which means p or a raw html opening tag.
 parent = NULL //optional of course, if set to the name of another group, 
 then the group becomes a child of the referenced group.
 )

 Then I create an associative array of options for the form.
 Finally, I call the class constructor with the three arrays as params.

 The class provides me with a few nifty functions:
 * toHtml();
 (do I need to explain?)
 * toArray();
 Returns the inputs, options, and groups inside a single array, with the 
 value altered when necessary
 * wasSubmitted();
 Does some guesswork to see if the form was submitted, there's a lot of 
 smart automagicness inside.
 * runAutoChecks();
 Runs the checks he can, like the validity of emails in 'type' = 'email' 
 inputs, pattern validation for input with a set pattern, required inputs, 
 fills the error array with error messages, sets class[]='error' to wrongly 
 filled inputs...
 * wasValidInput();
 Returns true if none of the autochecks or eventual manual checks returned 
 an error.

 And it works like this:
 [...]
 if ($form-wasSubmitted()){
 $form-runAutoChecks();
 /* Additional non-automatable controls */
 // None in this case
 if ($form-wasValidInput()){
 // success, do stuff
 } else {
 // show errors and form again
 }
 } else {
 echo $form-toHtml();
 }

 There are other things I didn't list, like the fact that ever input has 
 options to specify a wrapper (class and id are associated to the wrapper 
 if it's defined), the form encoding automatically changes in case of a 
 file input, etc etc etc...

 The types are abstracted enough that one could easily make a function that 
 automatically creates the code for a first draft of the forum out of the 
 db schema of an eventual table. Of course you'd have to provide error 
 messages, remove unnecessary inputs, adding new ones...

Your ideas are similar to mine, but I have a much more advanced 
implementation which involves the use of a Data Dictionary. After building a 
database table I import the structure into my data dictionary, then export 
it to create a database table class and a table structure file. Still using 
the data dictionary I can then build the family of transactions to maintain 
that database table. This uses a standard set of page controllers and XSL 
templates to build the HTML. So within 5 minutes I can run the transactions 
to list, search, add, enquire, delete and update that database table without 
having to write a single line of SQL or HTML. In most cases I don't even 
have to write a single line of PHP. Is your method as fast as that?

All this functionality exists within the Radicore framework, so you can 
download it and try it for yourself.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Forms validation and creation- easier solution?

2009-05-23 Thread Stephen

Tony Marston wrote:
Your ideas are similar to mine, but I have a much more advanced 
implementation which involves the use of a Data Dictionary. After building a 
database table I import the structure into my data dictionary, then export 
it to create a database table class and a table structure file. Still using 
the data dictionary I can then build the family of transactions to maintain 
that database table. This uses a standard set of page controllers and XSL 
templates to build the HTML. So within 5 minutes I can run the transactions 
to list, search, add, enquire, delete and update that database table without 
having to write a single line of SQL or HTML. In most cases I don't even 
have to write a single line of PHP. Is your method as fast as that?


All this functionality exists within the Radicore framework, so you can 
download it and try it for yourself.
  

Thank you!

I am moving out of do it hand to learn how it is done into how can I 
get this work done quickly and well

and you point me to Radicore!

Stephen


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Forms validation and creation- easier solution?

2009-05-21 Thread Daniele Grillenzoni

On 20/05/2009 9.03, Angelo Zanetti wrote:

Hi all.



We have done quite a few projects and we are looking to find better ways to
implementing forms.



Forms seem to be quite time consuming and repetitive.



Generally are there any classes or libraries that will assist with:



1.  Easy creation of forms (fields and layout)

2. Validation of specific fields within the forms (server side not JS)

3. Decrease in time required to setup the forms pages

any other comments are welcome.



Thanks in advance

Angelo


Elemental
http://www.elemental.co.zahttp://www.elemental.co.za/

Dynamic Web and Mobile Solutions








Personally I created a little Class that handles it.

First I create an array of associative arrays, every associative array 
represents an input of an abstract type (similar to the webforms, 
meaning i have stuff like type=telephone).


Stuff like
$inputs[]=array(
name = foobar,
required = true,
type = string,   // text is reserved to textarea
label = Foo Bar,
error_required = you need to provide a Foo Bar value, dummy,
group = main
);
etc.

Then I create an array for groups.
$group[main] = array(
	type = block, // types are either block which means div, set 
which means fieldset, paragraph which means p or a raw html opening tag.
	parent = NULL		//optional of course, if set to the name of another 
group, then the group becomes a child of the referenced group.

)

Then I create an associative array of options for the form.
Finally, I call the class constructor with the three arrays as params.

The class provides me with a few nifty functions:
* toHtml();
(do I need to explain?)
* toArray();
	Returns the inputs, options, and groups inside a single array, with the 
value altered when necessary

* wasSubmitted();
	Does some guesswork to see if the form was submitted, there's a lot of 
smart automagicness inside.

* runAutoChecks();
	Runs the checks he can, like the validity of emails in 'type' = 'email' 
inputs, pattern validation for input with a set pattern, required 
inputs, fills the error array with error messages, sets class[]='error' 
to wrongly filled inputs...

* wasValidInput();
	Returns true if none of the autochecks or eventual manual checks 
returned an error.


And it works like this:
[...]
if ($form-wasSubmitted()){
$form-runAutoChecks();
/* Additional non-automatable controls */
// None in this case
if ($form-wasValidInput()){
// success, do stuff
} else {
// show errors and form again
}
} else {
echo $form-toHtml();
}

There are other things I didn't list, like the fact that ever input has 
options to specify a wrapper (class and id are associated to the wrapper 
if it's defined), the form encoding automatically changes in case of a 
file input, etc etc etc...


The types are abstracted enough that one could easily make a function 
that automatically creates the code for a first draft of the forum out 
of the db schema of an eventual table. Of course you'd have to provide 
error messages, remove unnecessary inputs, adding new ones...


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php