Jump to content

[SOLVED] How can I add custom fields to new user registration?


AFemaleProdigy
 Share

Recommended Posts

I am trying to add several new custom fields that the user can fill out during the registration process, which will then be attached to the ps_customer table with the rest of their information. I have created the new tables in the DB with no problem. If I manually enter values in the DB via phpmyadmin, I am able to get them to show up in the customer view/list and other BO pages, but the functions to add the values through the registration process are not working.

 

I have attempted to follow the instructions at the link below and do believe I did it all exactly as instructed. However, I am getting the same error that the last two people were getting and I can't get the registration process to complete. It gets stuck on "An error occurred while creating your account."

 

http://www.prestashop.com/forums/topic/113300-tutorial-add-custom-field-to-customer-registration-how-you-found-us-store-in-db-display-result-in-admin/

 

I haven't been able to get any assistance on that thread, so I am making a new one.

 

I also was trying to get the page to output the actual error for troubleshooting, but I can't get that to work either.

 

Can anyone see any fault in those instructions that would cause problems with 1.4.7.3? Maybe something is missing or should be written differently? Any help would be greatly appreciated.

 

Thanks!

Share this post


Link to post
Share on other sites

Thanks, Mike. I went through those steps as well, but still get the same error. The custom fields show up with no problem, but when the user tries to submit the Login step (contact info, address, login), the user is redirected back to the same page with the same error message. Is there some way to determine what the actual error is? It is a general error message with no details.

 

Also, I was able to add the new custom fields to BO which not only displays their value, but I am also able to edit them in BO now. I just can't get the authentication process to move to the next step during registration.

Share this post


Link to post
Share on other sites

I have an easier way of doing this, if your form and fields are different from that of "My Account" and need a specific form for your site/business I would be happy to help. On my demo site you can see the example of the form I am talking about.

  • Like 2

Share this post


Link to post
Share on other sites

  • 3 months later...

this not just closeer to the jesica problem,...

 

I would like to

 

1. add additional field to my presta registration.,

2. this field is county

 

This field will a county field, that should be optionaly field coresponding to the county list in the dbasae.

 

Could someone here help me to do this...??

 

I have tried edit some , in authentication.tpl, but nothing still happened...

 

Is there some thing logicaly solving to do that..

 

thx..vy mu :rolleyes:

Share this post


Link to post
Share on other sites

  • 4 months later...

this not just closeer to the jesica problem,...

 

I would like to

 

1. add additional field to my presta registration.,

2. this field is county

 

This field will a county field, that should be optionaly field coresponding to the county list in the dbasae.

 

Could someone here help me to do this...??

 

I have tried edit some , in authentication.tpl, but nothing still happened...

 

Is there some thing logicaly solving to do that..

 

thx..vy mu :rolleyes:

 

Have you tried to make form costumization throught control panel?

 

Go to Localization > Country > Choose the Country you want to customize > edit the "address layout" fields adding or deleting field

 

Hope this help

Edited by RobboR (see edit history)

Share this post


Link to post
Share on other sites

  • 3 weeks later...

this not just closeer to the jesica problem,...

 

I would like to

 

1. add additional field to my presta registration.,

2. this field is county

 

This field will a county field, that should be optionaly field coresponding to the county list in the dbasae.

 

Could someone here help me to do this...??

 

I have tried edit some , in authentication.tpl, but nothing still happened...

 

Is there some thing logicaly solving to do that..

 

thx..vy mu :rolleyes:

 

 

To add county to the addresses, you have to do the following:

 

in override/classes/Address.php, add these lines:

 

<?php

class Address extends AddressCore
{
/** @var string county */
public $county;

/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'address',
'primary' => 'id_address',
'fields' => array(
'id_customer' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_manufacturer' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_supplier' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_warehouse' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_country' =>  array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_state' =>  array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
'alias' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'company' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
'lastname' =>  array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'firstname' =>  array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
'vat_number' =>   array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'address1' =>  array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
'address2' =>  array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
'postcode' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
'city' =>  array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
'county' =>  array('type' => self::TYPE_STRING, 'validate' => 'isCountyName', 'size' => 64),
'other' =>  array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
'phone' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 16),
'phone_mobile' =>  array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 16),
'dni' =>  array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16),
'deleted' =>  array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'date_add' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
'date_upd' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
),
);
}

?>

 

Then add Validation in override/classes/Validate.php:

<?php
class Validate extends ValidateCore
{
/* Check for city name validity
 *
 * @param string $city City name to validate
 * @return boolean Validity is ok or not
 */
public static function isCountyName($county)
{
 return empty($county) || preg_match('/^[a-zA-Z -]+$/', $county);
}
}
?>

 

Then in your theme template files, there are several places you'll need to add the following or similar code:

	{elseif $field_name eq "county"}
	<p class="text county">
	  <label for="county">{l s='County'}</label>
	  <input type="text" class="text" name="county" id="county" value="{if isset($guestInformations) && $guestInformations.county}{$guestInformations.county}{/if}" />
	</p>

.. That last bit of code, or similar versions of it need to be inserted into the following template files:

order-opc-new-account.tpl

authentication.tpl

address.tpl

authentication-create-account.tpl

 

 

….Then you need to add the 'county' field for each county that you want it to appear. Go to Localization > Country > Choose the Country you want to customize > edit the "address layout" fields adding 'county' as a field.

 

You will also need add an extra field into the table ps_address in yout phpMyAdmin:

ALTER TABLE `ps_address` ADD `county` VARCHAR( 64 )

 

Then

Edited by TommyKaneko (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 1 month later...

Hi,

 

I've created module that will allow add extra fields to registration form. With that module you can easily create unlimited number of additional fields and sections on top and bottom of the registration form. The advantage of that module is that it doesn't override or change any core files.

 

Please check it here:

http://addons.presta...tom-fields.html

 

Regards,

modulesmarket.com

Edited by modulesmarket (see edit history)

Share this post


Link to post
Share on other sites

  • 2 months later...

I have just successfully added a custom field to the user registration screen using this guide posted by dinofratelli, however there is one step missing in the guide.

 

 

http://www.bitsandchips.it/forum/viewtopic.php?f=11&t=4884

 

in classes/Customer.php

around line 160

public static $definition = array(
...
'passwd' =>	  array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 32),

Below this line, add this line

'referralcode' =>	 array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),

 

Works like a charm vor ver. 1.5.4.0

 

Neller

  • Like 2

Share this post


Link to post
Share on other sites

  • 1 month later...

Hy, is it posibile to add a limit for new custom fields? For example i want to add a custom field name CNP ( personal numeric code) wich must have exactly 13 numbers. Ex: 1860219001122, and also if a customers puts 10 numbers, to display a message like "Incorrect CNP" ? I want this field to be *, mandatory.

 

How do i make this custom field visible in a customer order? To see the CNP of a customer, after he did an order, i must go in the clients section and look for it;...

Also, the new field created is not visible if i press edit from admin on a customer. In front office in my account, also the new field is not displayed.

 

I have added some pics also

 

This tutorial is great, but it also needs some more customizations on custom field added...and i lack some skils :(

 

I.ve managed to add the custom field on front office customer informations by editing the identity.tpl from my theme, but i don;t know how to make it display the values inserted. I thing it hs something to do with {$smarty.post. . For example the name wich is displayed has a smarty.post.firstname. I think i must add smarty.post.referralcode to somewher but don;t know were...

 

I've put the code in identity.tpl :

 

<label for="referralcode">{l s='CNP'}</label>

<input name="referralcode" type="text" class="text" id="referralcode" value="{$smarty.post.referralcode}"/>

</p>

 

But the field remains empty after i press save. If i replace $smarty.post.referralcode} with $smarty.post.firstname} after i press save it displays the name. So this mean , at least i think, it has something to do with phpmyadmin and the sql database, but don;t know what to do in database.. pls anyone help...

post-584131-0-30706500-1372706952_thumb.png

post-584131-0-73727100-1372706968_thumb.png

post-584131-0-54563900-1372706970_thumb.png

Edited by anukku (see edit history)

Share this post


Link to post
Share on other sites

  • 2 months later...

Hy, is it posibile to add a limit for new custom fields? For example i want to add a custom field name CNP ( personal numeric code) wich must have exactly 13 numbers. Ex: 1860219001122, and also if a customers puts 10 numbers, to display a message like "Incorrect CNP" ? I want this field to be *, mandatory.

 

How do i make this custom field visible in a customer order? To see the CNP of a customer, after he did an order, i must go in the clients section and look for it;...

Also, the new field created is not visible if i press edit from admin on a customer. In front office in my account, also the new field is not displayed.

 

I have added some pics also

 

This tutorial is great, but it also needs some more customizations on custom field added...and i lack some skils :(

 

I.ve managed to add the custom field on front office customer informations by editing the identity.tpl from my theme, but i don;t know how to make it display the values inserted. I thing it hs something to do with {$smarty.post. . For example the name wich is displayed has a smarty.post.firstname. I think i must add smarty.post.referralcode to somewher but don;t know were...

 

I've put the code in identity.tpl :

 

<label for="referralcode">{l s='CNP'}</label>

<input name="referralcode" type="text" class="text" id="referralcode" value="{$smarty.post.referralcode}"/>

</p>

 

But the field remains empty after i press save. If i replace $smarty.post.referralcode} with $smarty.post.firstname} after i press save it displays the name. So this mean , at least i think, it has something to do with phpmyadmin and the sql database, but don;t know what to do in database.. pls anyone help...

 

Hi!!! I 've the same problem as you. How have you solved? 

 

Thanks!!!

Edited by RobinsondMantua (see edit history)

Share this post


Link to post
Share on other sites

Anukku, i think that i solved it. I am a newbie in this kind of enviroment. Consecuently, i don´t know if this solution is the best solution, but after a few tests that seems to be working. 

 

Here we go!

 

 

- In themes\default\identity.tpl, add the following lines just before the line {if $newsletter}

 

<p class="text">
<label for="referralcode">{l s='Referral code'}</label>
<input name="referralcode" type="text" class="text" id="referralcode" value="{$referralcode}"/>
</p>
 
- In controllers\front\IdentityController.php :
 
  - In the method "initContent" add the following line
 
$referralcode=$this->context->cookie->customer_referralcode; 
 
after the line 
 
parent::initContent();
 
 
In the same method, add the line 
 
$this->context->smarty->assign('referralcode', $referralcode);
 
before the the line
 
$this->setTemplate(_PS_THEME_DIR_.'identity.tpl');
 
  - In the method "postProcess" add the following line
 
$this->customer->referralcode = Tools::$this->customer->referralcode;
 
after the line 
 
$this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
 
and add the line
 
$this->context->cookie->customer_referralcode = $this->customer->referralcode;
 
after the existing line
 
$this->context->cookie->customer_firstname = $this->customer->firstname;
 
 
Please, test it and tell me something. :)
Edited by RobinsondMantua (see edit history)
  • Like 2

Share this post


Link to post
Share on other sites

  • 2 months later...
  • 2 months later...

I have an easier way of doing this, if your form and fields are different from that of "My Account" and need a specific form for your site/business I would be happy to help. On my demo site you can see the example of the form I am talking about.

Hello.

     Where is your demo site link.?

Share this post


Link to post
Share on other sites

  • 6 months later...
  • 1 year later...
  • 9 months later...

Hi friends,

   While users try to create an account there is an error code "There is 1 error 1.optin is required." that get them stuck and i have tried all areas to troubleshoot and it seems effortless.

 

Kindly help

Share this post


Link to post
Share on other sites

  • 7 months later...
  • 2 weeks later...

How can I add custom fields to newsletter?

i bought Pop Newsletter v1.3.2. How to configure custom fields in this module? Or maybe I have to buy another module.........

My blocknewsletter.tpl:

}
<!-- Block Newsletter module-->
<div id="newsletter_block_left" class="block">
	<h4>{l s='Newsletter' mod='blocknewsletter'}</h4>
	<div class="block_content">
		<form action="{$link->getPageLink('index', null, null, null, false, null, true)|escape:'html':'UTF-8'}" method="post">
			<div class="form-group{if isset($msg) && $msg } {if $nw_error}form-error{else}form-ok{/if}{/if}" >
				<input class="inputNew form-control grey newsletter-input" id="newsletter-input" type="text" name="email" size="18" value="{if isset($msg) && $msg}{$msg}{elseif isset($value) && $value}{$value}{else}{l s='Enter your e-mail' mod='blocknewsletter'}{/if}" />
                <button type="submit" name="submitNewsletter" class="btn btn-default button button-small">
                    <span>{l s='Ok' mod='blocknewsletter'}</span>
                </button>
				<input type="hidden" name="action" value="0" />
			</div>
		</form>
	</div>
    {hook h="displayBlockNewsletterBottom" from='blocknewsletter'}
</div>
<!-- /Block Newsletter module-->
{strip}
{if isset($msg) && $msg}
{addJsDef msg_newsl=$msg|@addcslashes:'\''}
{/if}
{if isset($nw_error)}
{addJsDef nw_error=$nw_error}
{/if}
{addJsDefL name=placeholder_blocknewsletter}{l s='Enter your e-mail' mod='blocknewsletter' js=1}{/addJsDefL}
{if isset($msg) && $msg}
	{addJsDefL name=alert_blocknewsletter}{l s='Newsletter : %1$s' sprintf=$msg js=1 mod="blocknewsletter"}{/addJsDefL}
{/if}
{/strip}

Share this post


Link to post
Share on other sites

  • 3 months later...

Hello Folks,

  Am presently working on a new project, i want to create a product page and list them under a sub category of a category but it's not showing me the drop down option category to choos for a sub category.

 

I will appreciate if i can get help on how to re solve this problem.

 

Cheers...

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More