You can also just look at the Wix CRM API Reference and you would have found a suitable example for yourself there, which uses a onClick event handler function instead of the onAfterSave.
https://www.wix.com/corvid/reference/wix-crm.html#createContact
Create a contact and then send a Triggered Email to the new contact
import wixCRM from 'wix-crm';
$w.onReady(function () {
$w("#myButton").onClick( () => {
wixCRM.createContact( {
"firstName": $w("#firstName").value,
"lastName": $w("#lastName").value,
"emails": [$w("#email").value],
"phones": [$w("#phone").value]
} )
.then( (contactId) => {
wixCRM.emailContact("thankyou", contactId, {
"variables": {
"firstName": $w("#firstName").value,
"lastName": $w("#lastName").value
}
} );
} );
} );
} );