is not used any more and exists only for history. Post new tickets on the Github account. n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Last modified 10 years ago

#1071 assigned enhancement

jForms : add methods to the API to help manage reference count introduced in #876 fix — at Initial Version

Reported by: bricet Owned by:
Priority: normal Milestone:
Component: jelix:forms Version: trunk
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:


Since #876 fix, jForms now have an internal counter to manage multiple create without any delete. This could happen, for example, if a user opens several browser windows/tabs of the same Jelix page. What is expected from the user is to be able to use whatever window/tab he wants, may be several if your application can handle with that.

So the use of JForms in that case is quite different.

For exemple, to avoid data overlap between several windows/tabs, you may want to clear() a jForm after making a fill() (if entered data is not accepted by your app). Destroy() only decrements the counter. You may want to destroy all instances, so add a destroyAllInstances(). You may also want to know how many instances of a form where created with getInstancesCount().

There is also a clean() method which exists but is not documented, as far as I know.

With those 3 additional methods, you could use jForms as is :

  • prepare : create() a jForms, whatever get() is (you may test getInstancesCount() if you want to avoid to many creations). Multiple create() on a given selector won't bloat $_SESSION since it just increments a counter. You may clean() before create() to remove old instances.
  • show : if you need to, setData() to some fields, fetch() your template assigning him the form and then clear() the form. This prevents multiple jForms data overlap
  • save : fill() your form. If there are data errors, clear() it and redirect to show(). If everything is OK, store your data or whatever you have to do with them, clear() your jForms and go to "end"
  • end : destroy() your jForms

In some place of your code, for example when a user connects, you can call destroyAllInstances() - with no args - to make sure all instances of all forms are destroyed.

Change History (1)

Changed 12 years ago by bricet

Patch to introduced 3 new methods

Note: See TracTickets for help on using tickets.