Hi..
I am kinda new with Modx and need your advise on how can I save extended fields OnUserFormSave event?
Below code can get the existing extended fields value and display it inside an input element, but when I Save, it doesn't want to save the value back to the database.. Could any one help please?
How can I debug? echo "something" or var_dump('something') is not showing anything in OnUserFormSave block.
Many thanks!
switch ($modx->event->name) {
case 'OnUserFormPrerender':
/* if you want to add custom scripts, css, etc, register them here */
break;
case 'OnUserFormRender':
$account_type = '';
$portfolio_no = '';
if (isset($scriptProperties['user'])) {
$profile = $user->getOne('Profile');
$fields = $profile->get('extended');
$account_type = $fields['account_type'];
$portfolio_no = $fields['portfolio_no'];
}
/* now do the HTML */
$fields = '
<div class="x-form-item x-tab-item">
<label class="x-form-item-label" style="width:150px;">Account type</label>
<div class="x-form-element">
<input type="text" name="account_type" value="' . $account_type . '" class="x-form-text x-form-field" />
</div>
</div>
<div class="x-form-item x-tab-item">
<label class="x-form-item-label" style="width:150px;">Portfolio number</label>
<div class="x-form-element">
<input type="text" name="portfolio_no" value="' . $portfolio_no . '" class="x-form-text x-form-field" />
</div>
</div>
';
$modx->event->output($fields);
break;
case 'OnUserFormSave':
/* do processing logic here. */
$profile = $user->getOne('Profile');
$fields = $profile->get('extended');
$fields['account_type'] = $_POST['account_type'];
$fields['portfolio_no'] = $_POST['portfolio_no'];
$profile->set('extended', $fields);
$profile->save();
break;
}
return;