Hi Blai,
It would good to get more details - what exactly does not work? Saving? Registration? Both? In the Preview mode/published site?
Here you can find detailed guide on configuring Custom Registration form - Velo Tutorial: Creating a Custom Registration Form with Code | Help Center | Wix.com,
Also the API reference for the register() function can be useful - Page Not Found - Velo API Reference - Wix.com
As for your code - you might have few issues:
- “_id”: wixUsers.currentUser.id line can throw an exception if there will be no logged in user (apparently that is the case - we are talking about the Registration form, right?)
Try to remove this line. You can get the new user ID in the result returned by the register() function.
In general, to debug the code - wrap it within try-catch block and print out the error in occurs. That is:
$w.onReady(function(){
$w('#register').onClick(function (){
try{
.... your code
} catch (error) {
console.error(`Error occurred: ${error}`);
}
})
})
-
Note that the register() function may work only in Published site mode, in in the Preview mode.
-
Try to add .catch() blocks to both results - from the registration and from the save - and print out the error if occurs.
-
Despite the fact the requests for register and save are sent in parallel (they are asynchronous), it might be a good idea to perform the redirect only after both operations are completed. (It can be achieved by nesting register request into the .then of the save one, or other way around, or by waiting for both promises)
-
Make sure you grant sufficient permissions to write data to the Company collection.