Decide if class attribute is required on the fly

Author Message

Thomas Nunninger

Sunday 22 May 2005 12:41:44 am

Hi,

my users have the possibility to register as user in different roles: normal user, affiliate, company. I added a multi select attribute to my user class where users can choose for which role they want to register. Also I added all possible attributes needed for the different roles, like company name (affiliates and companies), newslettermode (normal users), ...

Now I want to ensure - for example - that a user, who wants to register as company or affiliate, fills in the company name.

I had some different ideas:

- set the needed attributes to "required" on the fly (not in the database)

- add an workflow after validating / before saving the new user object

- a new datatype "requireOnTheFly" which is somehow depending on one source attribute (e.g. checkbox set) and then checks if some target attributes are not empty

What do you think? Any other idea?

Thanks

Thomas

Paul Forsyth

Sunday 22 May 2005 5:57:26 am

You could also use javascript to check on the dependancy if you can use js.

Ini files may be preferrable to specific options in the class.

paul

Thomas Nunninger

Sunday 22 May 2005 8:20:47 am

Wtih JavaScript I'm not sure if someone deactivated it...

> Ini files may be preferrable to specific options in the class.

I don't understand what you want me to tell :(

Paul Forsyth

Sunday 22 May 2005 10:14:37 am

Take this ini setting i've made up, say in site.ini:

[RequiredClassAttributes]
RequiredAttributes[]=
RequiredAttributes[]=99

And in your template you could try with:

{let requiredAttributes=ezini("RequiredClassAttributes","RequiredAttributes","site.ini")
   myClassAttributeID=$myAttribute.contentclassattribute_id}

{section show=or($requiredAttributes|contains($myClassAttributeID),$myAttribute.contentclass_attribute.is_required)}
Hey, im required.
{section-else}
Im not required.
{/section}

{/let}

I feel this is a little easier to do than with the class system or with a workflow.

Hope it helps!

Paul

Thomas Nunninger

Sunday 22 May 2005 11:50:35 am

Thank you for this good idea with the ini file.

The only problem: when validating the input, eZ publish itself won't check if there is input given in the additional required fields because they are not defined as required in the class definition. One solution (but not very nice): declare all attributes as required and fill e.g. the company name with nonsens in a hidden HTML input field if it is a normal user.

Any better idea. Am I right, that there is no simple way to tell eZ publish "When validation this user's data consider the attribute 'company name' as required."

Thomas

Paul Forsyth

Sunday 22 May 2005 12:08:33 pm

Putting a workflow for before user/register would allow you get by this but its a little messy to implement :(

I've used hidden fields in the past to 'prefill' such information. You could use the example code i gave earlier to decide whether to show a proper input field or a hidden one. And set the hidden field to 'No company'. If the text is suitable its not actually too bad.

If you dont this information shown to users you could always test for this string, and whether anything was chosen in your other attributes, and show or not show in other templates.

Paul

Thomas Nunninger

Sunday 22 May 2005 12:26:47 pm

Thank you. I think I will find a solution.

Have a nice evening

Thomas

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 06:02:33
Script start
Timing: Jan 19 2025 06:02:33
Module start 'layout'
Timing: Jan 19 2025 06:02:33
Module start 'content'
Timing: Jan 19 2025 06:02:34
Module end 'content'
Timing: Jan 19 2025 06:02:34
Script end

Main resources:

Total runtime0.7021 sec
Peak memory usage4,096.0000 KB
Database Queries69

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 589.2891152.6406
Module start 'layout' 0.00610.0035 741.929739.4766
Module start 'content' 0.00960.6910 781.4063555.8750
Module end 'content' 0.70050.0015 1,337.281316.1250
Script end 0.7021  1,353.4063 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4570160.0002
Check MTime0.00130.1881160.0001
Mysql Total
Database connection0.00090.123910.0009
Mysqli_queries0.625389.0632690.0091
Looping result0.00080.1104670.0000
Template Total0.667095.020.3335
Template load0.00190.270520.0009
Template processing0.665094.719620.3325
Template load and register function0.00020.026910.0002
states
state_id_array0.00270.387210.0027
state_identifier_array0.00090.123920.0004
Override
Cache load0.00170.2381480.0000
Sytem overhead
Fetch class attribute can translate value0.00070.100720.0004
Fetch class attribute name0.00180.262680.0002
XML
Image XML parsing0.00230.326220.0011
class_abstraction
Instantiating content class attribute0.00000.0037110.0000
General
dbfile0.00330.4758160.0002
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs