Jump to content

Adding new field to registration, won't insert to database


gumbotron

Recommended Posts

Hi,

 

I am still trying to add one simple field to the customer registration form in PS 1.6.  I'm following Nemo's great tutorials here, using the "Adding extra fields to other Object types" section, but when I finish and try to register using the new field, it is not inserted into the database.  Dev Mode shows no errors.

 

What I've done so far is:

 

  • created a new database text field "newfield"
  • created a new file, Customers.php, in "override/classes" with the following code:
Class Customer extends CustomerCore
{
    public $newfield;
	public function __construct($id = null)
	{
		$this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP');
		parent::__construct($id);
	}
}
  • copied the "renderForm()" method from "controllers/admin/AdminCustomersController.php" to "override/controllers/admin/AdminCustomersController.php", changed the last line to "return AdminController::renderForm();" and added this to the copied array list:
array(
    'type' => 'text',
    'label' => $this->l('Our new field:'),
    'name' => 'newfield',
    'size' => 64
),

I then added the html for the newfield to the authentication.tpl file in my theme. 

 

The field shows up in the registration form, but when I sign up, there is only NULL in the database for that new field. 

 

Please help?

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

Ok, I see what happened.  I guess I assumed the Customers and Products class definitions were different (based on a misreading of the tutorial), so I was going to the Customers.php, searching for __construct() and using that function (the only __construct() function in Customers.php) for the override.  When I use the same __construct() function as in your tutorial, everything works fine.

Thank you, Nemo!

Edited by gumbotron (see edit history)
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...