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