XF 2.2 Make Location show on registration form as optional - not as required

Mr Lucky

Well-known member
Currently the Location field only shows on the registration form if you make it a required field. So if you make location optional, it doesn't show on the form.

I would like it to show there but allow the user to have the option to show it or not. Does anyone know of a way to do this e.g. with a template edit?

Thanks
 
Currently the Location field only shows on the registration form if you make it a required field. So if you make location optional, it doesn't show on the form.

I would like it to show there but allow the user to have the option to show it or not. Does anyone know of a way to do this e.g. with a template edit?

Thanks

I ran into a similar thing many many years ago.

I worked around it with custom fields, which can be set up here on this extension of your URL: admin.php?custom-user-fields/

For context, this is my setup and how it appears on registration.
0lbbdxZ.png


akUMlx5.png

It might not look or do exactly what you want it to but hope you find it somewhat helpful as a workaround until someone with an actual fix comes alone :)
 
Template register_macros

Code:
<xf:if is="$xf.options.registrationSetup.requireLocation">
    <xf:textboxrow name="{$fieldName}" value="{$value}" required="true"
        label="{{ phrase('location') }}"
        hint="{{ phrase('required') }}" />
</xf:if>

Change that so it suits your needs.
 
Template register_macros

Code:
<xf:if is="$xf.options.registrationSetup.requireLocation">
    <xf:textboxrow name="{$fieldName}" value="{$value}" required="true"
        label="{{ phrase('location') }}"
        hint="{{ phrase('required') }}" />
</xf:if>

Change that so it suits your needs.
Thanks @Kirby that’s what I assumed but I haven't been able to find exactly what I need to do. I can change required to false, but the Location field only shows on the registration form if you make it required in Setup > Options : Registration.

And if you have that set to required in order make the field show on the form, and set required="false" in register_macros then the form will still not complete if left blank even though it now says optional due to the edits in register_macros.
 
Last edited:
This may help ?

 
Thanks @Kirby that’s what I assumed but I haven't been able to find exactly what I need to do.
Is it really that complicated?

There is one condition to only show the field if is is configured to be required, so the first step is to remove that condition:
Code:
<xf:if is="$xf.options.registrationSetup.requireLocation">
    <xf:textboxrow name="{$fieldName}" value="{$value}" required="true"
        label="{{ phrase('location') }}"
        hint="{{ phrase('required') }}" />
</xf:if>

becomes

Code:
<xf:textboxrow name="{$fieldName}" value="{$value}" required="true"
    label="{{ phrase('location') }}"
    hint="{{ phrase('required') }}" />

Now the field is always shown but it is still labled as required and it is required, so let's change that as well:
Code:
<xf:textboxrow name="{$fieldName}" value="{$value}"
    label="{{ phrase('location') }}"
    hint="{{ phrase('optional') }}" />

And that's it (well, at least it should - I didn't actually test this).
 
No I worked it out eventually with a bit of trial and error.
did what was mentioned work?
i would like to have it as an option for people joining and not force it on them also.
i think i can muck around in the templates some now as i have been playing with some on my site and those seemed to have worked.
 
Back
Top Bottom