Forums / Developer / Decide if class attribute is required on the fly

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

eZ debug

Timing: Jan 20 2025 04:12:14
Script start
Timing: Jan 20 2025 04:12:14
Module start 'content'
Timing: Jan 20 2025 04:12:14
Module end 'content'
Timing: Jan 20 2025 04:12:14
Script end

Main resources:

Total runtime0.0311 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0124 590.4297180.8125
Module start 'content' 0.01240.0079 771.2422102.0547
Module end 'content' 0.02030.0107 873.296978.7031
Script end 0.0310  952.0000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00288.9452120.0002
Check MTime0.00123.9316120.0001
Mysql Total
Database connection0.004313.988010.0043
Mysqli_queries0.003210.363140.0008
Looping result0.00000.058320.0000
Template Total0.010233.010.0102
Template load0.00154.705310.0015
Template processing0.008828.226710.0088
Override
Cache load0.00092.865710.0009
General
dbfile0.00051.7024100.0001
String conversion0.00000.021530.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0003 secs