Help with Wix Location to

HI

can some one help me with my code and tell me what i have done wrong here i want to send the user to the home page after the code has run

many thanks

F

import {sendEmail} from 'backend/email';

import wixLocation from 'wix-location';

$w.onReady(function () {

});

export function submitCheckinButton_click(event, $w) {

// sendEmail is called with: email provider name (like:gmail), template id (like "thanks_for_interest") and params.

// params holds ALL variables for your email: sender name/email, recipients, cc´s, bcc´s, subject, body and more specific

// values to fill the template, like, in our example, Arrival, Departure and Remarks.

 let myprovider = "gmail";       //use her the alias you used for this service in emailJS

 let mytemplate = "check_ins";  //use her the template name you defined in emailJS

 let myparams = {

 "from_email": $w("#emailAddress").text,

 "to_email": "Krays23@hotmail.com",

 "replyto_email": $w("#emailAddress").text,

 "weight": $w("#currentWeight").value,

 "fat": $w("#fatInpercentage").value,

 "comments": $w("#howTheyfelt").value,

 "name": $w("#fullName").text,

 "date": $w("#checkInDate").value,

 "front_photo": $w("#frontPhotoupload").value,

 //"cc_email": "foo3@bar.com",

 //"Arrival": "25-03-2018",

 //"Departure": "28-03-2018",

 //"Remarks": "Could we have coffee instead of tea for breakfast?",

 //"from_Name": "Giri´s Code Corner"
        };
 
    sendEmail (myprovider, mytemplate, myparams);

    $w('#checkInUploadBox').show();
    $w('#checkInsWrite').setFieldValue('name', $w('#fullName').text);
    $w('#checkInsWrite').setFieldValue('emailAddress', $w('#emailAddress').text);
    $w("#checkInsWrite").save();
    $w('#checkInsWrite').onAfterSave(()=>{ 
 
    wixLocation.to("/home")

    })
 
}

Hi Fraser,
You don’t need the " before & after home. You need ` before & after it. You could also consider adding a ; after wixLocation . to ( “/home” ). Your code should look like this:

wixLocation.to('/home');

Hey @fraser :raised_hand_with_fingers_splayed:

The onAfterSave() event handler should be placed inside the dataset’s onReady() function.

$w.onReady(() => {
    $w("#myDataset").onReady(() => {
        $w("#myDataset").onAfterSave( () => {
              wixLocation.to('/home');
        });
    })
})

That’s the right way to implement the event handler, in your code it’s not working because you’re telling the code “what to do after saving” after the save is already done, the above way will ensure that the after save instructions are set as soon as the page finish loading.

Hope this helps~!
Ahmad

His line is completely correct, and there’s no difference between (’ ') and (" ") or even the ( ) in this particular case.

And not using the semicolon won’t break anything.

@ahmadnasriya oh, sorry.

@arthurvalatin It’s okay, thanks for trying to help :blush:

awesome many thanks

@fraser You’re welcome :wink: