1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Making a field recognized in registration form

Discussion in 'XenForo Development Discussions' started by Kirk, Apr 28, 2015.

  1. Kirk

    Kirk Well-Known Member

    So i'm trying to add the ability to allow users to upload an avatar on registration but the input name i have right now is saying Avatar is not a valid field. I'm assuming i need to extend the Register underneath the public controller to make it a valid field? Could anyone correct me on this?
     
  2. Kirk

    Kirk Well-Known Member

    Bump
     
  3. Nobita.Kun

    Nobita.Kun Well-Known Member

    In your html class. Add this class: OptIn. It will ignore validator errors.
     
    Kirk likes this.
  4. Kirk

    Kirk Well-Known Member

    I get the same error.

    The field 'avatar' was not recognised.
     
  5. Nobita.Kun

    Nobita.Kun Well-Known Member

    What is position of class you put? Give your code here :)
     
  6. Kirk

    Kirk Well-Known Member

    I did a template modification for the registration_form

    Find:
    Code:
    <xen:if is="mt_rand(0, 2) == 1">
        <dl class="ctrlUnit limited">
            <dt><label for="ctrl_{$fieldMap.email_hp}">{xen:phrase email}:</label></dt>
            <dd>
                <input type="email" name="{$fieldMap.email_hp}" value="" dir="ltr" class="textCtrl" autocomplete="off" id="ctrl_{$fieldMap.email_hp}" />
                <p class="explain">{xen:phrase please_leave_this_field_blank}</p>
            </dd>
        </dl>
        </xen:if>
    
    Replace
    Code:
    $0
        <dl class="ctrlUnit">
            <dt><label>{xen:phrase upload_avatar}:</label></dt>
            <dd><input type="file" class="OptIn" name="avatar"/></dd>
        </dl>
    
     
  7. Nobita.Kun

    Nobita.Kun Well-Known Member

    Try it:
    Code:
    <dl class="ctrlUnit OptIn">
            <dt><label>{xen:phrase upload_avatar}:</label></dt>
            <dd><input type="file" name="avatar"/></dd>
        </dl>
    If not work. You can use the name avatar_date instead of avatar
     
  8. Kirk

    Kirk Well-Known Member

    Tried that it doesn't throw an error. However after registration it shows the default avatar.
     
  9. Nobita.Kun

    Nobita.Kun Well-Known Member

    Look up on your code. While registering user_id =0 so... :)
     
    Kirk likes this.
  10. Kirk

    Kirk Well-Known Member

    So i'm guessing i have to create a public controller for the registration?
     
  11. Kirk

    Kirk Well-Known Member

    I have a feeling i`m doing something for my ControllerPublic/Register

    PHP:
    <?php
    class KK_avatarOnRegistration_ControllerPublic_register extends XFCP_KK_avatarOnRegistration_ControllerPublic_register
    {
        public function 
    applyAvatar()
        {
            
    $userid $this->_
            
    //Grab image from user
            
    $avatar $this->_input->filterSingle('avatar_date'XenForo_Input::UINT);

            
    //create instance of XenForo's User's DataWriter
            
    $dw XenForo_DataWriter::create('XenForo_DataWriter_User');

            
    //Set the field with the data we filtered
            
    $dw->set('avatar_date'$avatar);

            
    //Lets save into the database
            
    $dw->save();

            
    //Lets send a response to the user, so he knows everything is A OK
            
    return $this->responseRedirect(
                
    XenForo_ControllerResponse_Redirect::SUCCESS,
                
    $this->getDynamicRedirect()
            );
        }
        
    /**
         * Grab XenForo Avatar Model
         * @return getMdelFromCache
         */
        
    protected function _getAvatarModel()
        {
            return 
    $this->getModelFromCache ('XenForo_Model_Avatar');
        }
    }
     

Share This Page