This is one way of doing it
https://experienceleague.adobe.com/docs/experience-manager-learn/forms/adaptive-forms/custom-submit-aem-forms-article.html?lang=en
or you can do it this way
https://experienceleague.adobe.com/docs/experience-manager-learn/forms/handling-af-form-submissions/submitting-ad...