Advertisement:

Author Topic: How to register a field in the user profile?  (Read 231 times)

Xefiron

  • Newbie
  • *
  • Posts: 32
  • Software developer - Desarrollador de software
How to register a field in the user profile?
« on: May 09, 2019, 09:51:46 pm »
Inside user-profile.php I have added the following code:

Code: [Select]
<?php if(osc_user_type() == '0') { ?>
  <div class="row">
    <label for="new_field"><span><?php _e('New field''stela'); ?></span><span class="req">*</span></label>
    <div class="input-box"><i class="fa fa-address-card-o"></i><?php CustomForm::newfield_text_register(osc_user()); ?></div>
  </div>

  <div class="row">
    <label for="user_type"><?php _e('User type''stela'); ?></label>
    <div class="input-box"><i class="fa fa-industry"></i><?php UserForm::is_company_select(osc_user()); ?></div>
  </div>
<?php ?>

This is the code of the newfield_text_register() function:

Code: [Select]
static public function newfield_text_register($user = null) {
  if( Session::newInstance()->_getForm('newfield') != '' ) {
    $user['s_newfield'] = Session::newInstance()->_getForm('newfield');
  }
  parent::generic_input_text("newfield", isset($user['s_newfield'])? $user['s_newfield'] : '', null, false);
}

Finally, inside the UserActions.php, at the end of prepareData() function i set this code:

Code: [Select]
if($input['b_company'] == 1) {
  $input['s_newfield'] = Params::getParam('newfield');
}

What I'm looking for is that when the user is of type 0 and select to be type 1, the new field will appear, and he will have to complete it, after that that value of the new field will be registered in the database, but what happens is that only when the selection of the user type does not change (that is, when it is still 0) if the changes made in the other fields are changed and saved, but when selecting type 1 the new field appears, but its value is not saved changes made in the other fields. Any idea what can be treated?