View previous topic :: View next topic |
Author |
Message |
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Sat Apr 19, 2003 2:50 pm Post subject: Formsess: forms handling with Smarty |
|
|
A few month ago, i had sent a message on the mailing list about a sort of "forms framework" i had written to work with Smarty. It has been developped a little since then, used by 2 or 3 developers, and I think I can offer it here again.
The website is not back yet since my personal server had some problems and is still sleeping under the desk... if it's requested I'll setup a website again.
First, my app. has bugs, missing features, no or not enough documentation. If you can do with it, you can read further on
Formsess is a set of plugins, prefilters and php classes / functions used to handle forms and forms data across pages when using smarty.
A set of custom XHTML tags, very similar to HTML Form tags, let you create forms in your templates. The data from each form is then handled by a class that will be used to store the data in a session dataspace, validate the data, and so on.
In fact, you can write all your forms without caring about the "value" "selected" or "checked" part, all of that is handled in the PHP script.
You can download the files needed by formsess here:
http://www.katana-inc.com/formsess/formsess.zip
There is no README nor INSTALL files, i've gotta create them (in fact a lot of work was done but my CVS repository was LOST).
Anyway, the setup is not complex: keep the libs directory as is, but you can rename it (a little like smarty's libs dir). The Smarty_fs file contains the definition of a class that extends smarty and is used to automatically include formsess' files. It's not mandatory but of course it's cleaner that way.
The prepend file creates the Smarty_fs object and assigns 2 paths.
And finally, the config.inc.php file is included by prepend.php and contains 2 config vars.
This is my own file setup, you can change it to whatever you want, as long as the logic is the same, formsess will just work the same way.
I have written a quick sample script / template. It has not beed tested, sorry, i'll fix that later.
You can find the sample files in the archive in /samples/. It just displays a basic form with several elements, and when data is submited, it saves the values then redirects to the form.
Ask here if you need help, I'll answer as soon as possible.
If you find bugs I'll be glad to fix them.
And if you have suggestions, I'll listen.
Hope it helps.
Edit:
An anonymous CVS is now available:
CVSROOT=:pserver:anonymous@cvs.phpedit.net:/cvs/formsess
no password
I'm not sure what I'm doing is interesting but I'll keep on working on it
Last edited by katana on Mon Apr 21, 2003 6:41 am; edited 1 time in total |
|
Back to top |
|
dak Smarty n00b
Joined: 16 Apr 2003 Posts: 1 Location: Russia, Moscow
|
Posted: Sat Apr 19, 2003 7:52 pm Post subject: |
|
|
Can you translate all comments in all files from french to english. For exmaple in files: Smarty_fs.class.php and formsess.class.php and may be in another files? |
|
Back to top |
|
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Sat Apr 19, 2003 8:00 pm Post subject: |
|
|
Huhu sorry; yes, of course. I've developed the application itself in english so that it can be easily distributed, but these files were originally written for another project.
I'm currently working on setting up a CVS for the project, it should be up with an anonymous acces on monday.
And I'll update the zip file with "translated" files. |
|
Back to top |
|
ronan Smarty n00b
Joined: 18 Apr 2003 Posts: 4
|
|
Back to top |
|
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Sun Apr 20, 2003 10:17 am Post subject: |
|
|
In fact i first developped a simple form validation class, then extended it to store the data between pages then added the direct interaction between the templates and the data. So it was written for me, and now that it looks usable i just want to share it.
Now for the two scripts you talk about: i didn't write this to make something better than the other scripts. I wanted something that allowed good interaction with smarty. What I can say about formsess is that it makes the work for templates designer very easy, without having to learn any (or very few) tags, since the tags used by formsess are almost identical to classical HTML tags. I think that the main difference is a philosophical one |
|
Back to top |
|
muppie Smarty Rookie
Joined: 27 Apr 2003 Posts: 20
|
Posted: Sun Apr 27, 2003 4:52 pm Post subject: |
|
|
I developed my Form class... and thought about making it a smarty plugin.... however I ended up with something like this:
$smarty->assign('form', $form->build());
and in the template:
Code: |
{if $form.finished}
Dear {$form.values.first_name}, thank you for submitting your details.
{else}
{$form.start}
<table>
<tr>
<td>{$form.labels.first_name}</td>
<td>{$form.controls.first_name}</td>
</tr>
<tr>
<td>{$form.prev}</td><td align="right">{$form.next}</td>
</tr>
</table>
{$form.end}
{/if}
|
So it ended up not needing any special smarty plugins. Just plain old smarty support for nested arrays.
The form class supports multiple page handling with next/previous, data validation (by using as many callback functions as needed), possible logic in determining which page to go when user click next for example to skip a page if user clicks "pay with credit card" - it will go to CC page otherwise it will display where to send the check.
If there is any error in the form, {$form.labels.first_name} for example will be shown red, or other means to indicate error. Combined with smarty it becomes very flexible depending on how you want to display things around. |
|
Back to top |
|
muppie Smarty Rookie
Joined: 27 Apr 2003 Posts: 20
|
Posted: Sun Apr 27, 2003 5:00 pm Post subject: |
|
|
Manuel Lemos' is nice with javascript validators too, but I found it very hard to use / set up a form or even to learn it. If you think I'm wrong please correct me.
I've never seen smartyforms closely... isn't it lemos' wrapper for smarty?
I looked hard for form generation/validation class before I wrote mine. There's HTML_OOH_FORM and HTML_QuickForm in Pear. Quick Form wasn't flexible enough (it defines the output html) and OOH was.... hard to use (for me) |
|
Back to top |
|
jorgerpo Smarty n00b
Joined: 15 Jun 2003 Posts: 3
|
Posted: Thu Jun 26, 2003 6:18 pm Post subject: |
|
|
Your approach seems great muppie. Would you like to share it? |
|
Back to top |
|
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Fri Jul 04, 2003 9:41 am Post subject: |
|
|
Sorry, for some reason I didn't get an email for your reply.
The "official" website for formsess is http://www.katana-inc.com/formsess/
It is still missing a solid documentation, but there is one already. Don't hesitate to ask if you have any question. |
|
Back to top |
|
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Thu Aug 21, 2003 7:38 pm Post subject: |
|
|
In order to keep the post up to date, I'll add a new version was released (2.0.0 RC2) and a real documentation is now available on the website (http://www.katana-inc.com/formsess)
Several nice features are being added, like dynCalendar integration (DHTML calendar from phpguru.org which allows quick & easy selection of a date for a html_select_date field) |
|
Back to top |
|
muppie Smarty Rookie
Joined: 27 Apr 2003 Posts: 20
|
Posted: Sat Sep 13, 2003 1:19 pm Post subject: |
|
|
jorgerpo wrote: | Your approach seems great muppie. Would you like to share it? | Unfortunately I am not planning to release this class.
Last edited by muppie on Sun Sep 28, 2003 1:13 pm; edited 1 time in total |
|
Back to top |
|
Justin Smarty Regular
Joined: 07 May 2003 Posts: 38 Location: Vilnius, Lithuania
|
Posted: Sun Sep 28, 2003 12:50 pm Post subject: |
|
|
I spent all day with formsess and smarty.. and what can I say.. it's great!
waiting for new formsess versions and features _________________ http://www.baubas.net |
|
Back to top |
|
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Fri Oct 03, 2003 7:25 am Post subject: |
|
|
Whoa, thanks a lot justin. That's the kind of reply that gives you the will to develop
Can I use your post as a testimony on the site ? |
|
Back to top |
|
Justin Smarty Regular
Joined: 07 May 2003 Posts: 38 Location: Vilnius, Lithuania
|
Posted: Fri Oct 03, 2003 9:50 am Post subject: |
|
|
katana wrote: | Can I use your post as a testimony on the site ? |
yes:)
now I'm trying to find a solution, how to make error message multilanguage.. have you any ideas? _________________ http://www.baubas.net |
|
Back to top |
|
katana Smarty Rookie
Joined: 17 Apr 2003 Posts: 26 Location: France
|
Posted: Fri Oct 03, 2003 10:04 am Post subject: |
|
|
I usually use Smarty configuration files for multilanguage, so using:
<fs:validate field="fieldname" check="empty" message="{#errormessage_fieldname_empty#}" />
would work.
However, there is something I need to fix with quotes escaping at the moment, so you'd better avoid single quotes inside the messages |
|
Back to top |
|
|