Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

I'm not a sexist...

...but I need to force gender selection at registration. Any advice on how do that?

There was an error rendering this rich post.

Best Answer

Answers

  • peregrineperegrine MVP
    edited April 2013

    isn't gender selection already there?

    what version of Vanilla and what type of registration?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited April 2013

    ok you probably mean vanilla 2.1? since it has an unspecified option.

    a whole less searching if the exact version of vanilla was specified in question :)

    one way to do it....

    e.g. with registerapproval

    copy the

    /applications/dashboard/views/entry/registerapproval.php

    to your theme views

    and modify

    echo $this->Form->RadioList('Gender', $this->GenderOptions, array('default' => 'u'))

    so that the $this->GenderOptions are only M F or whatever you want.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited April 2013

    or create a plugin and copy the registration views. either way will do what you want.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • lifeisfoolifeisfoo ✭✭✭
    edited April 2013

    Thank you for your answer.

    I have tried using using various hooks and this code:

    SetValue("GenderOptions", $Sender, array( 'm' => T('Male'), 'f' => T('Female') ));

    Without success.

    This is the vanilla EntryController function that sets these values:

    `
    public function Register($InvitationCode = '') {
    $this->FireEvent("Register");

      $this->Form->SetModel($this->UserModel);
    
      // Define gender dropdown options                                                        
      $this->GenderOptions = array(
         'u' => T('Unspecified'),
         'm' => T('Male'),
         'f' => T('Female')
      );
    

    //CUT...
    }
    `

    As you can see an event is triggered before the values set, so it is unuseful. So I tried with the immediatily next event (and the code reported above):
    EntryController_BeforeAddCss_Handler without results...

    Since I don't want to mantain vanilla custom views, I'm too busy and too lazy :), I'm searching for another solution...maybe javascript?

    There was an error rendering this rich post.

  • I found this tid bit of info maybe it can help?

    http://www.html-form-guide.com/php-form/php-form-processing.html

    maybe if you add an if statement

    if(empty($varGender)) {
          $errorMessage .= "You forgot to select your Gender!";
    
    
  • SrggamerSrggamer ✭✭✭

    Thanks! For asking this... Did not feel manly enough to ask.

  • lifeisfoolifeisfoo ✭✭✭

    I have also tried to add a custom validation in the controller using hooks to enforce this solution, but nothing.
    Thank you everybody.

    There was an error rendering this rich post.

  • SrggamerSrggamer ✭✭✭

    @lifeisfoo said:
    I have also tried to add a custom validation in the controller using hooks to enforce this solution, but nothing.
    Thank you everybody.

    This would be really cool.

  • peregrineperegrine MVP
    edited April 2013

    I added a ForceGender plugin that gives only m and f f choices and removes unspecified

    and validates for selection of m and f.

    http://vanillaforums.org/addon/forcegender-plugin

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @lifeisfoo and @srgamer

    try version 1.1 - see if it works for you

    http://vanillaforums.org/addon/forcegender-plugin

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • SrggamerSrggamer ✭✭✭

    @peregrine said:
    lifeisfoo and srgamer

    try version 1.1 - see if it works for you

    http://vanillaforums.org/addon/forcegender-plugin

    Its Srggamer, thats why I never got notifications

  • Its Srggamer, thats why I never got notifications

    @Srggamer

    try version 1.1 - see if it works for you

    http://vanillaforums.org/addon/forcegender-plugin

    consider yourself notified - if you were serious about the plugin, download and test.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited April 2013

    I'll add an icon - when @vrijvlinder posts her icon picks :).

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • SrggamerSrggamer ✭✭✭
    edited April 2013

    Dear @peregrine you serve another fine meal, works as wanted, works flawlessly and Even has a settings page. Great work mate!

  • @peregrine said:
    I'll add an icon - when vrijvlinder posts her icon picks :).

    lmao you read my intentions, Yep on it's way !! let me post a couple before you add it to the plugin so as to pick the best one....

  • lifeisfoolifeisfoo ✭✭✭

    Thank you @peregrine, it works. Here is the code to manage profile updates (force users already registered users with no gender selected to select a gender on profile update). Add it to your plugin.

        public function UserModel_BeforeSaveValidation_Handler($Sender){
            $Gender = GetValue("Gender", $Sender->EventArguments["FormPostValues"]);
            if ( !in_array($Gender, array('m','f')) ){
                echo $Gender;
                $Sender->Validation->AddValidationResult('Gender', T('You must select a Gender M or F'));
            }
        }
       public function ProfileController_BeforeEdit_Handler($Sender) {
           $NewGenderOptions = array("m"=>"Male", "f"=>"Female");
           $Sender->GenderOptions =  $NewGenderOptions;
       }
    
    

    Sharing knowledge is always a pleasure.

    There was an error rendering this rich post.

  • I though this would be relevant to this discussion for some reason...

Sign In or Register to comment.