AMPscript in CloudPages Form

%%[
    VAR @firstName, @lastName, @email
    SET @firstName = RequestParameter("firstName")
    SET @lastName = RequestParameter("lastName")
    SET @email = RequestParameter("email")

    /* Insert data into Data Extension */
    InsertDE("YourDataExtension", "FirstName", @firstName, "LastName", @lastName, "Email", @email)
]%%

SSJS to Fire the Event

<script runat="server">
    Platform.Load("Core", "1");

    var firstName = Request.GetFormField("firstName");
    var lastName = Request.GetFormField("lastName");
    var email = Request.GetFormField("email");

    var payload = {
        "ContactKey": email,
        "EventDefinitionKey": "YOUR_EVENT_DEFINITION_KEY",
        "Data": {
            "FirstName": firstName,
            "LastName": lastName,
            "Email": email
        }
    };

    var url = "https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com/interaction/v1/events";
    var contentType = "application/json";
    var headerNames = ["Authorization"];
    var headerValues = ["Bearer YOUR_ACCESS_TOKEN"];

    var result = HTTP.Post(url, contentType, Stringify(payload), headerNames, headerValues);
    Write("Result: " + result.StatusCode);
</script>