Hi Johanna
Something to get yourself familiar with is reading the Wix API documents which will tell you what functions to call and with what arguments.
In your code you have decided to use wix-users.register().
Let’s take a look at the API documentation for this function.
register( )
Registers a new site member.
function register(email: String, password: String, [options: RegistrationOptions]): Promise
Description
The register() function returns a Promise that resolves to a RegistrationResult object when the user is either registered or is pending registration.
So breaking this call down: function register( email : String, password : String, [ options : RegistrationOptions]): Promise
Register takes three arguments in this order email, password, options. So to begin with, when you call register you should always have email and password as your first two arguments.
So now let’s look at the third argument options . This is shown with square brackets [] . These signify that the argument is optional and so doesn’t need to be there if you don’t need it. We do so let’s have a look and see why.
Now email and password are typed as String which we can handle easily. We need to figure out how to create this thing called RegistrationOptions . Well let’s look at the documentation for RegistrationOptions:
RegistrationOptions
An object that contains information about a site registration.
Type
Object
Properties
contactInfo ContactInfo Contact information.
So RegistrationOptions are really just the same ContactInfo that is typically used with the wix-crm.createContact function. Let’s look at the ContactInfo documentation.
ContactInfo
An object that contains information about a site contact.
Type
Object
Properties
firstName String - Contact's first name.
lastName String - Contact's last name.
picture String - Contact's image source.
emails String[ ] - List of contact's email addresses.
loginEmail String - Email address the contact who is also a member uses to log into the system.
phones String[ ] - List of contact's phone numbers.
labels String[ ] - List of contact's labels. Labels are used to organize contacts. When setting the labels property, you can only list labels that already exist in your site's Contacts List.
language String - Contact's language.
customFields String | - Any number of custom fields. Customs fields are
Number | - used to store additional information about your
Date - site's contacts. When setting a custom field, use key:value pairs where the key matches the names defined in your site's Contacts List. You can only set values for custom fields that already exist in the Contacts application.
Now you have the following properties that you are trying to save into the CRM using register: FullName, Credentials, Practise, StateProvince, Country. The problem we have is that the properties that are available to us in the ContactInfo object are not listed as the ones you want. You could map FullName to firstName and lastName but that might not meet your needs.
This is what the customFields property is for. Custom fields allows you to create a special object containing the custom fields that you want to add to your CRM. IMPORTANT NOTE: These fields MUST be predefined in your CRM for this to work. So if you haven’t created the custom fields for FullName, Credentials, Practise, StateProvince, Country in your contacts then you need to do this or the code I propose below will not work.
OK so let’s fix your code!
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady(function () {
$w('#register').onClick(function () {
let FullName = $w('#Full Name').value;
let Credentials = $w('#Credentials').value;
let Practice = $w('#Practice').value;
let StateProvince = $w('#StateProvince').value;
let Country = $w('#Country').value;
let email = $w('#email').value;
let password = $w('#password').value;
// Here we create the contactInfo Object
let contactInfo = {
"emails": [email],
"FullName": FullName,
"Credentials": Credentials,
"Practice": Practice,
"StateProvince":StateProvince,
"Country":Country
};
// Include the contactInfo in registration
wixUsers.register(email, password, contactInfo) .then(() => {
wixLocation.to('/thanks');
});
});
});
//TODO: write your page related code here..
export function register_click(event) {
$w('#register');
}
Hopefully this will do what you want.
Now one last thing. These values will ONLY be available to you in the dashboard view of the contacts in your CRM. They will not be available to read from the CRM. To do this you will need to use your own local data collection.
Cheers
Steve