Database not combining into a single row for entries on a Velo/Corvid customized multi-step form even with code added to fix problem.

I should say “parsing error, unexpected token else”…mistyped.

parsing error, unexpected token else on line 40

Can you say wich line that exaclty is and the full codeblock (from the if statement until the last } to finish the codeblock

kind regards,
Kristof.

You are doing something wierd.
You end your if statement but want to start it again without && between it.
0 ) ( $w
Old:

 function checkContinue1() {
 if ($w('#firstname').value.length > 0 && $w('#lastname').value.length > 0 && $w('#email').value.length > 0) ($w('#company').value.length > 0 && $w('#companyAddress').value.length > 0 && $w('#city').value.length > 0) ($w('#state').value.length > 0 && $w('#zipcode').value.length > 0 && $w('#phone').value.length > 0)  
{
        $w('#button3').enable();
} else {
        $w('#button3').disable();
}
    }

New:

 function checkContinue1() {
 if ($w('#firstname').value.length > 0 && $w('#lastname').value.length > 0 && $w('#email').value.length > 0) ($w('#company').value.length > 0 && $w('#companyAddress').value.length > 0 && $w('#city').value.length > 0 && $w('#state').value.length > 0 && $w('#zipcode').value.length > 0 && $w('#phone').value.length > 0)  
{
        $w('#button3').enable();
} else {
        $w('#button3').disable();
}
    }

If you open { or } you always have to close it in the same function.
If you don’t do it it wil give an error in the code below ( it thinks its in the same function since the function isn’t added yet.

Kind regards,
Kristof.

@flatthead You have extra parentheses, misplaced brackets, and well - I understand, you’re learning.

Try this:

function checkContinue1() {
   if ($w('#firstname').value.length > 0 && $w('#lastname').value.length > 0 &&
     $w('#email').value.length > 0 && $w('#company').value.length > 0 &&
     $w('#companyAddress').value.length > 0 && $w('#city').value.length > 0 &&
     $w('#state').value.length > 0 && $w('#zipcode').value.length > 0 &&
   $w('#phone').value.length > 0) {
      $w('#button3').enable();
   }
   else {
      $w('#button3').disable();
   }
}

I didn’t test this as I don’t have a page with the same elements, but this should be OK.

< just noticed that Kristof gave the same answer in a previous post >

@volkaertskristof Thanks for the context and reference, that really helped me understand the code better and my errors!! I’ve carefully gone back through and rechecked and corrected any parsing errors that popped up. My code is showing no more red flag errors when I go through it line-by-line. However, when I run the preview as well as live attempt to fill out the form, it still will not engage/move past page 1 when I click on the “next page” button. It turns black for a few seconds, then goes back to red, however, I remain on the first page with the information inputted into the fields.

@flatthead Post your updated code so we can see what you’re doing. Your new code should look just like Kristof’s.

@yisrael-wix , @volkaertskristof

import wixData from 'wix-data';

$w.onReady(function () {
    $w("#statebox8").changeState("state1");
});
// check fields in State1 to enable Continue button
export function firstname_input(event) {
    checkContinue1();
}
export function lastname_input(event) {
    checkContinue1();
}
export function email_input(event) {
    checkContinue1();
}
export function company_input(event) {
    checkContinue1();
}
export function companyaddress_input(event) {
    checkContinue1();
}
export function city_input(event) {
    checkContinue1();
}
export function state_input(event) {
    checkContinue1();
}
export function zipcode_input(event) {
    checkContinue1();
}
export function phone_input(event) {
    checkContinue1();
}
 function checkContinue1() {
 if ($w('#firstname').value.length > 0 && $w('#lastname').value.length > 0 && $w('#email').value.length > 0 && $w('#company').value.length > 0 && $w('#companyaddress').value.length > 0 && $w('#city').value.length > 0 && $w('#state').value.length > 0 && $w('#zipcode').value.length > 0 && $w('#phone').value.length > 0)
 {
      $w('#button3').enable();
        } else {
        $w('#button3').disable();
    }
}
export function button3(event) {
    $w("#statebox8").changeState("state2");
    saveFormData();
}

export function subscriptionplan_input(event) {
    checkContinue2();
}
export function dropdown4_input(event) {
    checkContinue2();
}
export function otherindustry_input(event) {
    checkContinue2();
}
export function companywebsite_input(event) {
    checkContinue2();
}
export function fintechurl_input(event) {
    checkContinue2();
}
export function uploadlogo_input(event) {
    checkContinue2();
}
function checkContinue2() {
 if ($w('#subscriptionplan').value.length > 0 && $w('#industrytype').value.length > 0 && $w('#otherindustry').value.length > 0 && $w('#companywebsite').value.length > 0 && $w('#fintechurl').value.length > 0 && $w('#uploadlogo').value.length > 0)
 {
        $w('#button7').enable();
        } else {
        $w('#button7').disable();
    }
}
export function btnBack_click(event) {
    $w("#statebox8").changeState("state1");
}
 
export function button7_click(event) {
    $w("#statebox8").changeState("state3");
    saveFormData();
}
// check fields in State3 to enable Submit button

export function where_Will_Use_ScanCode_input(event) {
    checkContinue3();
}
export function want_Social_Share_input(event) {
    checkContinue3();
}
function checkContinue3() {
 if ($w('#textBox2').value.length > 0 && $w('#checkboxGroup2').value.length > 0)
 {
        $w('#button4').enable();
    } else {
        $w('#button4').disable();
    }
}
export function button9_click(event) {
    $w("#statebox8").changeState("state2");
}
export function button4_click(event) {
    $w("#statebox8").changeState("state4");
    saveFormData();
}
// check fields in State4 to enable Submit button

export function image1_input(event) {
    checkContinue5();
}
export function image2_input(event) {
    checkContinue5();
}
export function image3_input(event) {
    checkContinue5();
}
export function image4_input(event) {
    checkContinue5();
}
export function image5_input(event) {
    checkContinue5();
}
export function image6_input(event) {
    checkContinue5();
}
export function file1_input(event) {
    checkContinue5();
}
export function file2_input(event) {
    checkContinue5();
}
export function file3_input(event) {
    checkContinue5();
}
export function file4_input(event) {
    checkContinue5();
}
export function file5_input(event) {
    checkContinue5();
}
export function file6_input(event) {
    checkContinue5();
}

 function checkContinue5() {
 if ($w('#input53').value.length > 0 && $w('#input52').value.length > 0 && $w('#input49').value.length > 0 && $w('#input48').value.length > 0 && $w('#input58').value.length > 0 && $w('#input57').value.length > 0 && $w('#input56').value.length > 0 && $w('#input55').value.length > 0 && $w('#input54').value.length > 0)
{
        $w('#button5').enable();
    } else {
        $w('#button5').disable();
    }
}
export function backbtn10_click(event) {
    $w("#statebox8").changeState("state3");
}
export function button5_click(event) {
    $w("#statebox8").changeState("state5");
    saveFormData();
}

// check fields in State5 to enable Submit button
export function av_Link_1_input(event) {
    checkSubmit();
}
export function av_Link_2_input(event) {
    checkSubmit();
}
export function av_Link_3_input(event) {
    checkSubmit();
}
export function av_Link_4_input(event) {
    checkSubmit();
}
export function av_Link_5_input(event) {
    checkSubmit();
}
export function av_Link_6_input(event) {
    checkSubmit();
}
export function av_Link_7_input(event) {
    checkSubmit();
}
export function av_Link_8_input(event) {
    checkSubmit();
}
export function av_Link_9_input(event) {
    checkSubmit();
}
export function av_Link_10_input(event) {
    checkSubmit();
}
 function checkSubmit() {
 if ($w('#input53').value.length > 0 && $w('#input52').value.length > 0 && $w('#input49').value.length > 0 && $w('#input48').value.length > 0 && $w('#input58').value.length > 0 && $w('#input57').value.length > 0 && $w('#input56').value.length > 0 && $w('#input55').value.length > 0 && $w('#input54').value.length > 0)
  {
      $w('#button6').enable();
        } else {
        $w('#button6').disable();
    }
}
export function button10_click(event) {
    $w("#statebox8").changeState("state4");
}

export function button6_click(event) {
    $w("#statebox8").changeState("state5");
    saveFormData();
}


// action for Submit buttion

function saveFormData() {

 let toSave = {
 "firstname":     $w('#firstname').value,
 "lastname":    $w('#lastname').value,
 "email":    $w('#email').value,
 "company": $w('#company').value,
 "companyaddress": $w('#companyaddress').value,
 "city": $w('#city').value,
 "state":     $w('#state').value,
 "zipCode":    $w('#zipcode').value,
 "phone":    $w('#phone').value,
 "subscription_Plan":      $w('#subscriptionplan').value,
 "industry_Type":     $w('#industrytype').value,
 "other_Industry":    $w('#otherindustry').value,
 "company_Website":    $w('#companywebsite').value,
 "fintech_Url": $w('#fintechurl').value,
 "company_Logo": $w('#uploadlogo').value,
 "where_Will_Use_ScanCode":     $w('#textBox2').value,
 "want_Social_Share":    $w('#checkboxGroup2').value,
 "image1":      $w('#uploadButton33').value,
 "image2":     $w('#uploadButton28').value,
 "image3":    $w('#uploadButton34').value,
 "image4":    $w('#uploadButton27').value,
 "image5": $w('#uploadButton32').value,
 "image6": $w('#uploadButton25').value,
 "file1":     $w('#uploadButton31').value,
 "file2":    $w('#uploadButton25').value,
 "file3":      $w('#uploadButton29').value,
 "file4":     $w('#uploadButton24').value,
 "file5":    $w('#uploadButton30').value,
 "file6":    $w('#uploadButton23').value,
 "av_Link_1": $w('#input53').value,
 "av_Link_2": $w('#input52').value,
 "av_Link_3":     $w('#input51').value,
 "av_Link_4":    $w('#input49').value,
 "av_Link_5":    $w('#input48').value,
 "av_Link_6":    $w('#input58').value,
 "av_Link_7": $w('#input57').value,
 "av_Link_8": $w('#input56').value,
 "av_Link_9":     $w('#input55').value,
 "av_Link_10":    $w('#input54').value,
    };

    wixData.save("FormSubmissions", toSave) 
        .then((results) => {
 let item = results; //see item below
        })
        .catch((err) => {
 let errorMsg = err;
        });
}


@flatthead You should only call saveFormData() on the last state that has input - Submit. You are calling it for every state which means that every time you click the “Next” button, you save to the database. And you don’t even have all of the data yet.

Also maybe drop a screenshot of your State ID
Since it isn’t changing something has to be wrong.
saving the data early is bad since it adds data to the collection when not needed.
But it should still go to the next state

There is something else i noticed.
export function button3 ( event ) {
$w ( “#statebox8” ). changeState ( “state2” );
saveFormData ();
}

If you go to your propery menu when selecting button3, does it say button3 in the onClick event?


If the onClick() event has another name then button3 then it wont work.
It has to be button3 and not button3_click or something.

@volkaertskristof @yisrael-wix I’m so sorry, I am not sure what you mean by “don’t even have all the data yet”? Here is a screenshot of button 3 as well as what state 1 looks like (two separate photos b/c couldn’t capture it all on one.) There are 5 states.

@flatthead You have the following event handler:

export function button3(event) {
    $w("#statebox8").changeState("state2");
    saveFormData();
}

But in your screenshot, it shows the function name should be button3_click() - not button3().

Also, in this event handler, you call saveFormData(), but you haven’t even finished getting the input data from the other five form steps. You should only call saveFormData() at the end when the Submit button is clicked.

Seems like Yisrael beat me to it.

This you have:

export function button3 ( event ){ $w ( " #statebox8 " ). changeState ( “state2” ); saveFormData ();}

This it should be :

export function button3_click ( event ){ $w ( " #statebox8 " ). changeState ( “state2” );
;}

@volkaertskristof I think it’s a mistake to call saveFormData() on this button click. Need to wait for the other steps to complete.

Right, i just copied the previous code and changed the button3 to button_click.
But indeed the saveFormData() shoukd not be there. Only on the last button.
Edited the post.

@volkaertskristof @yisrael-wix You are both so patient and helpful, thank you so much. I have almost completely lost patience with myself. I removed the saveFormDate() from all sections but the submit section as suggested, as well as made the other change. Page 1 works! But now I can’t get past page 2. This time, the “next page” button will not even light up, stays gray, (but the back button works!) which I think is trying to tell me that the input fields are not all valid? I have gone through and double-checked for similar errors as before, also tried changing the two dropdown fields to on Change event handler (thought maybe it was the incorrect event for the type of field?) and back again to no avail.

Also, what is the correct code format when you want to make an input element optional?


For example, in the screenshot , I have all settings as “required” so that users can interact with the form, but there are inputs where not all users will have/need to input data. such as if they do not have a PayPal checkout link or if their industry does not fall in the “other” category.

I can’t directly see anything wrong.
Suggestion (only if you trust me)
Add me as cobtributer to your website (or make a copy and make me contributor there, this will only alow me to see that website nothing else)
This way i can see the code and change where needed. And test directly.
When i’m done i will come back here and post in detail what went wrong so others can see .
Email to add : kristof.print3d@gmail.com

This is at own risk since i’m just a forum ninja and not working with wix.

But it will alow me to help faster :slight_smile:

Kind regards,
Kristof.

@volkaertskristof sent invite