Jump to content

hookCreateAccountForm position


Recommended Posts


I use hookCreateAccountForm to add a field to the user registration form, just like that

public function hookCreateAccountForm ()
			return $this->display(__FILE__, 'myfield.tpl');

Obviously, this adds the field at the end.

Now, I was wondering if there is a way to change the position within the form:
for example, since mine is a B2B, it would be comfortable in "Company and VAT" block or immediately under the email field.
Is there a way to hook it elsewhere?


Link to comment
Share on other sites

Or alternatively I see that it also exists hook additionalCustomerFormFields but I can not find any practical examples of how I could use it for my purpose.

Does anyone have an example for me?


Note: I want to point out that this version of Prestashop does not override the customerformatter class, so which solutions to use as an alternative?

Edited by 2of7 (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 years later...

I use this trick to insert my field exactly where I want:

public function hookAdditionalCustomerFormFields($params)
        // your new field
        $rpps_field = (new FormField)
            //->setRequired(true) //Uncomment to set it mandatory
            ->setLabel($this->l('Label for the new field'));
		// insert the field into other fields, I choose to put it after teh birthday date
        $params['fields'] = $this->array_insert_after($params['fields'], 'birthday', ['rpps_id'=>$rpps_field]);
        // return empty array because the new field already added with current fields
        return [];

    function array_insert_after( array $array, $key, array $new ) {
        $keys = array_keys( $array );
        $index = array_search( $key, $keys );
        $pos = false === $index ? count( $array ) : $index + 1;
        return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );


Edited by sylvainlepetit
translate french comment to english (see edit history)
  • Like 1
  • Thanks 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...