There is no condition-based submit action in Sitecore Forms yet but you can achieve this by adding your custom action or using conditional logic for your forms. I have not tried this yet but I will suggest the conditional logic for this. The Sitecore Forms application lets you apply conditional actions to fields in web forms. You can apply conditions to ...
from your code getContact != null, if this condition is false, then you are creating new contact which is incorrect.
Contact contact = new Sitecore.XConnect.Contact(new ContactIdentifier(phoneAsChannel, contactus.email, ContactIdentifierType.Known));
Sitecore has already created an anonymous contact and set it in the device cookie ...
Goals of the current visit (interaction) are stored in the session and can be retrieved using Tracker API:
List<PageEventData> pageGoals = Sitecore.Analytics.Tracker.Current.Interaction.Pages
.SelectMany(p => p.PageEvents)
.Where(evt => evt.IsGoal)
If your forms are in AJAX mode, your issue is going to be that tracker is configured to not run on Forms Ajax mode. Not sure why.
At the top of your code, add this.
if (Tracker.Current == null && Tracker.Enabled)
Then do your normal xConnect code
var firstNameField = GetFieldById(data.FirstNameFieldId, ...
Similar to @Anton's example, you can achieve the same result with a Tag Manager solution.
Add an API to receive requests
Add Tag Manager
Content Authors can then create events/goals and trigger them on any action available with the Tag Manager
Sitecore GTM (API)
This repo, most ...