1
Shiva
Module development - AddElement
  • 2006/7/9 13:56

  • Shiva

  • Quite a regular

  • Posts: 280

  • Since: 2006/7/9 1


Hello all,

I am just starting out developing a XOOPS module and in PHP too.
I can see that AddElement is used to construct certain forms. Is this the preferred way of doing things. Can someone please explain the pros and cons. I guess the pros are more obvious - it can be done dynamically is probably the biggest one?
Is add/Element preferred for certain types of forms and not others - I ask because I can see that it is not consistently used and sometimes a template is used.

Thanks in advance.

2
Shiva
Re: Module development - AddElement
  • 2006/7/9 18:41

  • Shiva

  • Quite a regular

  • Posts: 280

  • Since: 2006/7/9 1


Anyone there?

3
Dave_L
Re: Module development - AddElement
  • 2006/7/9 21:12

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Using the XoopsForm class, and the related classes in /class/xoopsform/, which includes the addElement method, is the preferred way to create HTML forms in XOOPS.

It's part of the approach of separating content and presentation.

It's possible to use Smarty templates in conjunction with the XoopsForm classes; that gives you more control over the layout.

4
leostotch
Re: Module development - AddElement
  • 2006/7/9 21:31

  • leostotch

  • Just popping in

  • Posts: 76

  • Since: 2006/4/1 1


Quote:
Using the XoopsForm class, and the related classes in /class/xoopsform/, which includes the addElement method, is the preferred way to create HTML forms in XOOPS.
It's part of the approach of separating content and presentation.


From what I saw of the 2.3 code, skalpa didn't reuse XoopsForm anywhere, and IMHO he was right to make pages as he did.

XoopsForm actually fails to separate busyness logic from presentation logic, as it makes form elements created in PHP code, and thus prevents templates designer to have any real control on the presentation they want to have: if the programer decided that a field should be a selectbox, there is no way to use checkboxes or anything else instead.

The only advantage I see in XoopsForm is the fact it inserts Javascript validation code in the form... however you can obtain the same result by copying the code of the XoopsForm::renderValidationJS method and adapting it a little. You'll get cleaner and faster code (no need to include 120Kb of XoopsForm classes), as well as more customizable templates.

5
McNaz
Re: Module development - AddElement
  • 2006/7/9 22:12

  • McNaz

  • Just can't stay away

  • Posts: 574

  • Since: 2003/4/21


Hi Shiva.

I personally use Smarty for both my Admin and User pages and prefer not to use the Xoopsform class for one specific reason: I prefer to keep my presentation layer logic separate from my program logic and Smarty allows me to do this.

There are several benefits to this but the main one, at least for me, is the ability to break down form elements into smarty files and then re-use these as form building blocks.

HTH

Cheers

6
Shiva
Re: Module development - AddElement
  • 2006/7/10 8:35

  • Shiva

  • Quite a regular

  • Posts: 280

  • Since: 2006/7/9 1


Great thanks! Just the kind of advice I was looking for.
I will also use smarty templates. May as well stick to one standard way of doing things and it makes sense to clearly separate the interface from the logic.

7
birdseed
Re: Module development - AddElement
  • 2006/7/10 8:59

  • birdseed

  • Just popping in

  • Posts: 59

  • Since: 2005/2/26


Hi

There is a certain runtime overhead in using the XoopsForms which would be still worse is they were implemented as smarty templates. So xoopsforms are quite as they should be. Remember that smarty tends to be slow because every template has to be loaded from the file cache, checked it if need compilation, a lot of smarty logic, the plugin loader.... I don't start to talk about what a <{section}> tag does and how plugins are executed if they are not compile-time plugins.

I think the code/presentation separation arguments from McNaz are more like "I am a programmer and I do it my way" than what is really necessary. Generally, it is a good style to get HTML out of the php files and encapsulate your business logic into classes, but to not using xoopsforms because of some misunderstood rules...nonono. Use them, they allow you a good programming style.

The XOOPS core is not always consistent, this is quite ugly but usual if code has grown over the time. The most important rule I learned from 3 years of XOOPS programming: Try to understand XOOPS and try to understand the concepts, but stay pragratically.

greetings
birdseed

8
Shiva
Re: Module development - AddElement
  • 2006/7/10 9:29

  • Shiva

  • Quite a regular

  • Posts: 280

  • Since: 2006/7/9 1


Hi thanks for the alternative view there Birdseed.
Can you recommend a good practice how to create forms. I am briefly aware of form generators as formulize and formulaire, are these any good? Or is the best way just to develop manually?

Thanks again.

9
birdseed
Re: Module development - AddElement
  • 2006/7/10 9:45

  • birdseed

  • Just popping in

  • Posts: 59

  • Since: 2005/2/26


Hi

If you just want a simple answer form, use liaise or other modules. But you said you want to do your own module which looks like you have some custom stuff to do. So use Xoopsforms for that.

If you need highly flexible forms (e.g. with multiple colums) then you have to build your form with smarty from scratch.

greetings
bsm

10
McNaz
Re: Module development - AddElement
  • 2006/7/10 12:01

  • McNaz

  • Just can't stay away

  • Posts: 574

  • Since: 2003/4/21


Quote:
I think the code/presentation separation arguments from McNaz are more like "I am a programmer and I do it my way" than what is really necessary. Generally, it is a good style to get HTML out of the php files


Sorry but I have to disagree there. Especially the bit about "good style to get HTML out of the php files". It might have been good style ten years ago but we've (thankfully) moved on from the stone ages of PHP and HTML in one file.

These days you have common concepts such as MVC (Model-View-Controller) and 3-tier development methodologies.

Generally, you will find that your code is neater, compact, re-usable and easier to modify and maintain.

As for...

Quote:
There is a certain runtime overhead in using the XoopsForms which would be still worse is they were implemented as smarty templates.


I would imagine that Smarty templates consume less overhead due to the fact that Smarty caches and compiles php files. You also get the added bonus of not having HTML strewn all over your PHP file .

Login

Who's Online

431 user(s) are online (326 user(s) are browsing Support Forums)


Members: 0


Guests: 431


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits