Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

Form Validation on Registration form

In vanilla registration form, i have noticed that the validation of input fields is based in the fields of your table.

Now, i don't want the address, post code to be not required. What file do i need to edit? I'm using the register captcha form.

Best Answers

  • sahotataransahotataran Rare Visitor ✭✭
    Answer ✓

    you are going to have a little hard time to check out.

    all views are located in

    \applications\dashboard\views\entry
    1. select the view you have enabled - recaptcha or whichever u have.
    2. check the form action you have there - /entry/register
    3. look for the controller entry in /applications/dashboard/controllers
    4. look for class.entrycontroller.php
    5. look for function register in there and make changes
  • x00x00 Don't PM about development, I'm not currently taking on clients MVP
    Answer ✓

    look at the RegisterCaptcha method

    see

    $this->UserModel->Validation->ApplyRule('FieldName', 'RuleName');
    

    If you want to know how validation actually works look at

    forum/library/core/class.validation.php

    forum/library/core/functions.validation.php

    You can see the existing rules that you can use and you can add rules like so

    Validation->AddRule('RuleName','function:SomeFunction');
    

    you can also do regular expressions e.g.

    Validation->AddRule('RuleName','regex:`^[\d]{5}$`');
    
  • x00x00 Don't PM about development, I'm not currently taking on clients MVP
    Answer ✓

    @littlelorly

    Generally validation follows the schema, so if something is not required in the database, it is not required on the form. You can set the default value to null.

    I can't give in depth programming coaching, that is not really reasonable to expect this. I gave you the answer. I suggest you delve a little deeper, or pay someone to do it for you.

    Ideally you would avoid editing the core if you can, you can hook the user model if nessisary

  • x00x00 Don't PM about development, I'm not currently taking on clients MVP
    Answer ✓

    I read "i don't want the address, post code to be not required" to mean you wanted them to be required.

    But in any event first check your schema in the database before editing any code. The only reason why I added the addrule, bit is becuase stuff like post codes are often validated, but not necessarily required.

    I didn't really get from the OP what you wanted.

Answers

  • I have already looked at those files. But i don't see the script there that validates the input field.

  • sahotataran said: you are going to have a little hard time to check out.

    all views are located in

    \applications\dashboard\views\entry
    1. select the view you have enabled - recaptcha or whichever u have.
    2. check the form action you have there - /entry/register
    3. look for the controller entry in /applications/dashboard/controllers
    4. look for class.entrycontroller.php
    5. look for function register in there and make changes

    Hi, i looked for function register in the class.entrycontroller.php but i couldn't found it.

    Here is my form action:

    $this->Form->Open(array('Action' => Url('/entry/register'), 'id' => 'Form_User_Register', 'enctype' => 'multipart/form-data'));

    I'm using the registercaptcha form.

  • Hi x00, thanks for the response. This is the code in the recaptcha function that i saw:

    private function RegisterCaptcha() {
          include(CombinePaths(array(PATH_LIBRARY, 'vendors/recaptcha', 'functions.recaptchalib.php')));           
          if ($this->Form->IsPostBack() === TRUE) {             
          // Add validation rules that are not enforced by the model         
          //$this->UserModel->DefineSchema();    
          //print_r( $this->UserModel->Validation->Results());exit();
            // $this->UserModel->Validation->ApplyRule('Name', 'Username', $this->UsernameError);
             $this->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.'));
             $this->UserModel->Validation->ApplyRule('Password', 'Required');
             $this->UserModel->Validation->ApplyRule('Password', 'Match');
             // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge');
    
             if (!$this->UserModel->InsertForBasic($this->Form->FormValues())) {
                $this->Form->SetValidationResults($this->UserModel->ValidationResults());
                if($this->_DeliveryType != DELIVERY_TYPE_ALL) {
                   $this->_DeliveryType = DELIVERY_TYPE_MESSAGE;
                }
             } else {
                // The user has been created successfully, so sign in now
                $Authenticator = Gdn::Authenticator()->AuthenticateWith('password');
                $Authenticator->FetchData($this->Form);
                $AuthUserID = $Authenticator->Authenticate();           
    
                try {
                   $this->UserModel->SendWelcomeEmail($AuthUserID, '', 'Register');
                } catch (Exception $Ex) {
                }
    
                //$this->FireEvent('RegistrationSuccessful');
    
    
    
             }
    
          }
          $this->Render();
       }
    
  • What part should i edit here, so that the address, postcode and other fields of the form will not be required.

    Currently it requires all field to be filled in and that is what i saw in my recaptcha function.

  • Thank you X00, got your point. I just need to change the database settings. Set the fields to null. Thank you so much

Sign In or Register to comment.