Login  Register

Re: Validate Registration

Posted by Pedro on Nov 08, 2013; 8:39pm
URL: https://support.nabble.com/Validate-Registration-tp7587545p7587780.html

There are two steps: 1 - Create an exception message and 2 - edit validate_registration_form macro.
This is just my suggestion, you can use it to make your own message and code:
Step 1:
Override handle_registration_errors, adding the exception:
 <override_macro name="handle_registration_errors">
    <n.if.is_submitted_form>
        <then>
            <n.if.has_exception for="save-block">
                <then>
                    <n.handle_exception. for="save-block">
                        <div class="error-message important" style="margin:1em;padding:.5em 0">
                            <n.exception. name="user_is_not_member">
                                <t>You are not a Member.</t>                               
                            </n.exception.>
                            <n.exception. name="user_already_registered">
                                <t>You have already been registered.</t>
                                <a href="[n.forgot_password_path/]"><t>Forgot your password?</t></a>
                            </n.exception.> 
(...)

Step 2: Checking if the email given in the registration field is in the Members group:
<override_macro name="validate_registration_form">
    <n.users_in_group. group="Members">
        <n.set_var. name="in_members">
            <n.loop.>            
                <n.if.equal value1="[n.email_field.value/]" value2="[n.current_user.user_email/]">
                    <then>true<n.break/></then>
                </n.if.equal>            
            </n.loop.>
        </n.set_var.>
        <n.if.is_empty.remove_spaces.var name="in_members">
            <then.throw_template_exception name="user_is_not_member" />
        </n.if.is_empty.remove_spaces.var>
    </n.users_in_group.>
    
    <n.user_name_field.notify_if_empty/>
    <n.email_field.notify_if_empty/>
    <n.password_field.notify_if_empty/>
    <n.password2_field.notify_if_empty/>
    
    <n.if.not.equal value1="[n.password_field.value/]" value2="[n.password2_field.value/]">
        <then.throw_template_exception name="passwords_dont_match"/>
    </n.if.not.equal>  
    
    <n.if.not.accept_terms_field.is_checked>
        <then.throw_template_exception name="must_accept_terms_of_use"/>
    </n.if.not.accept_terms_field.is_checked>
    
</override_macro>
Let me know if you have any questions about the code.
My test forum.