Looking for help with a custom signup form. I am having members signup to my site where the first step passes their information (Firstname, Lastname, Email, City and State to the CRM, where they then hit a second button that submits the data to my website database, so I can store the data in both places. My problem is, I cannot get the city and state to pass to the CRM. Firstname, Lastname, email, and password work good, but no city and state. What do I need to change in the code to pass this to the contact on the CRM?
import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; $w.onReady(function () { $w('#register').onClick(function () { $w('#close').show(); $w('#text141').show(); let email = $w("#email").value let password = $w("#password").value let firstName = $w("#firstName").value let lastName = $w("#lastName").value let city = $w("#city").value let state = $w("#state").value // register as member using form data wixUsers.register($w('#email').value, $w('#password').value, { "contactInfo": { "firstName": $w('#firstName').value, "lastName": $w('#lastName').value, "city": $w('#city').value, "state": $w('#state').value } }); }); });
Hi Matthew:
CRM doesn't have a city and state property. You need to add these as Custom fields to the contact record before you can use them in the contactInfo field of the register. Check out how to do this here:
https://support.wix.com/en/article/adding-custom-fields-to-contacts
Then per the api documentation (ContactInfo)
Examples
Create a new contact with custom fields
import wixCRM from 'wix-crm'; // ... let firstName = // get first name let lastName = // get last name let email = // get email address let phone = // get phone number let contactInfo = { "firstName": firstName, "lastName": lastName, "emails": [email], "phones": [phone], "customField1": "customValue1", "customField2": "customValue2" }; wixCRM.createContact(contactInfo) .then( (contactId) => { // contact created } );
Now if you want full access to these properties then you are probably better off managing the data yourself unless this data is needed in your dashboard. The reason is that the wix-crm and wix-users APIs are not readable. You can only write to them. The only data that you have access to is the currentUser info which is an id, logged in status and email address. You will not be able to read your custom fields and will only be able to manage them by keeping duplicate copies in a data collection anyway.
So you may also want to take a look at this article:
https://support.wix.com/en/article/how-to-build-your-own-members-area-using-code
Steve