cyno - 3 weeks ago

Hi, I wanna have first name and last name in the registration form instead of display name. I've extended the RegisterFormBuilder, and changed the field. Everything works, but I want to save first name + last name as display name. Is there a way to do this in pyro, or with extending the RegisterFormHandler, or I just have to write a completely new handler, with the saving logic?

Answer

cyno - 3 weeks ago

Forgot to comment, but the solution is:


$this->getFormFieldFromAttribute('first_name')->value

ryanthompson - 3 weeks ago

You sure can! On your form builder - use something like this:

public function onSaving() {
    $this->setFormEntryAttribute(
            'display_name',
            $this->getFormEntryAttribute('first_name') . ' ' . $this->getFormEntryAttribute('first_name')
        );
}

cyno - 3 weeks ago

Tried doing this, but $this->getFormEntryAttribute('first_name') gives back null. Here is the code:


use Anomaly\UsersModule\User\Validation\ValidatePassword;
use Anomaly\UsersModule\User\Register\RegisterFormBuilder;

class ExtendRegisterFormBuilder extends RegisterFormBuilder
{
    protected $fields = [
        'first_name' => [
            'required' => true,
            'instructions' => false,
        ],
        'last_name' => [
            'required' => true,
            'instructions' => false,
        ],
        'username'     => [
            'instructions' => false,
        ],
        'email'        => [
            'instructions' => false,
        ],
        'password'     => [
            'instructions' => false,
            'type' => 'anomaly.field_type.encrypted',
            'rules'        => [
                'valid_password',
            ],
            'validators'   => [
                'valid_password' => [
                    'message' => false,
                    'handler' => ValidatePassword::class,
                ],
            ],
        ],
    ];

    public function onSaving()
    {
        $this->setFormEntryAttribute(
                'display_name',
                $this->getFormEntryAttribute('first_name') . ' ' . $this->getFormEntryAttribute('first_name')
            );
    }
}

cyno - 3 weeks ago

Forgot to comment, but the solution is:


$this->getFormFieldFromAttribute('first_name')->value

ryanthompson - 3 weeks ago

Glad you got it working! Go ahead and marked answered if you could so others can quickly spot it if needed. Thanks!