Connect registration input to collection

Hi Guys,
My mean purpose for this post is to add the input from registration into a created collection.
The difficulty in my code is that I already have a redirect to 3 different pages depending on the radio button selection in the register function. The codes after a direction are useless I assume because the member will already be redirected?
Can someone please help me?

Below the code of my registration lightbox:
import wixLocation from “wix-location” ;
import { register } from “backend/registration.jsw” ;
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import { authentication } from ‘wix-members’ ;

$w . onReady ( function (){

$w ( ‘#registerButton’ ). onClick ( ( Event ) => {
//to be sure all the fields are filled in:

if (![ “email” , “password” , “firstName” , “lastName” ]. every ( e => $w ( “#” + e ). valid )){
return $w ( “#fillInAllFieldsMsg” ). show ();
} else {
$w ( “#fillInAllFieldsMsg” ). hide ();
} //
const [ email , password , first , last ] = [ $w ( “#email” ). value , $w ( “#password” ). value , $w ( “#firstName” ). value ,
$w ( “#lastName” ). value ];

register ( email , password , {
contactInfo : {
“firstName” : first ,
“lastName” : last
}
},

  $w ( "#radioGroup1" ). selectedIndex ) 
. then (() => { 
   **const**  selectedValue  =  $w ( "#radioGroup1" ). value ; 

let targetPath = ‘/’ ;
switch ( selectedValue ){
case ‘Dronepiloot’ :
targetPath += ‘/dronepiloot-area’ ;
break ;
case ‘Klant’ :
targetPath += ‘/registratieOpdrachtgever/{email }’

break ;
case ‘Partner’ :
targetPath += ‘/ik-wil-partner-worden’ ;
break ;
}
wixLocation . to ( targetPath );
})
. catch (( error ) => {
console . log ( “error” , error );
});
wixData . insert ( “subscribers08” , {
“voornaam” : first ,
“naam” : last ,
“email” : email }
. catch ( ( err ) => {
console . log ( err );})

)})})

@russian-dima perhaps you could help me with this one too please?

Thank you!

Very weird code you are using here…

$w.onReady(function(){ 
	
    const [email, password, first, last] = [$w("#email").value, $w("#password").value, $w("#firstName").value, 
    $w("#lastName").value];

    //the same like...
    const [email, password, first, last] = ["x", "s", "d", "r"];
    console.log([email, password, first, last]);

    // why so complicated? Why not just...
    const myArray = ["x", "s", "d", "r"];

    // or in your case...
    const myArray =  [$w("#email").value, $w("#password").value, $w("#firstName").value, 
    $w("#lastName").value];

    console.log(myArray);
});

After inspecting your code…(using depricated Wix-Users-API)…

import wixUsers from 'wix-users';

$w.onReady(function(){ 
    $w('#registerButton').onClick( (Event) => {
        let myArray = [];
            myArray[0] = $w("#inpEmail");
            myArray[1] = $w("#inpPassword");
            myArray[2] = $w("#inpFirstname");
            myArray[3] = $w("#inpLastname");

            console.log("My-Array: ", myArray);
        myArray.forEach(element => {
            if(element.valid) {console.log("SUCCESS"); 
                start_Registration($w("#inpEmail").value, $w("#inpPassword").value, $w("#inpFirstname").value, $w("#inpLastname").value);
            }
            else {console.log("ERROR");}
        }); 
    });
});



function start_Registration(email, password, firstname, lastname) {
    wixUsers.register(email, password, {
        contactInfo: {
            "firstName": firstname,
            "lastName": lastname,
        }
    })
    .then((res) => {
        let resultStatus = res.status; console.log(resultStatus);
    });
}

First try to get this code-parts to work.

Than add the rest of your code to complete it.

Pay attention to the correct element-declarations!!!

inpEmail
inpPassword
inpFirstname
inpLastname

You will have to optimize this one…(adding a COUNTER which will count errors. If errors available, show error-msg, else continue CODE)…

myArray.forEach(element => {
    if(element.valid) {console.log("SUCCESS"); 
       start_Registration($w("#inpEmail").value, $w("#inpPassword").value, $w("#inpFirstname").value, $w("#inpLastname").value);}
});