App Builder \ Code Events

Before and After Submit

App Builder & Automation Expert

Stay Updated with ProcFu!

Subscribe to our newsletter for the latest tips, updates, and automation insights.

Subscribe Now
  • These are form submission events: one is executed before the form is submitted, and the other is executed after the form is submitted.
  • Both events are server-side and utilize ProcScript, providing access to the entire Functions API library.
  • Before Submit is triggered after a form submission but before the data is processed. It's ideal for data validation or manipulation, halting submissions with errors, or making last-minute adjustments.
  • After Submit occurs once the form has been processed and data saved, perfect for triggering follow-up workflows or actions, such as sending confirmation emails or redirecting users based on their input.
  • The following variables are available:
    • url_parameters: Provides an array of the parameters passed to the URL.
    • my_variables: Enables access to previously set variables and allows setting new ones.
    • custom_tokens: Access and set custom tokens here.
    • is_logged_in: Indicates whether a user is logged in (true) or not (false).
    • auth_item: Returns the authenticated user's item as raw JSON, including values, config, etc.
    • auth_item_values: Isolates just the data values from the "auth_item", omitting configuration details and other metadata.
  • Three additional variables are introduced here
    • form_action: The action being performed (create, update, delete, comment).
    • item_id: In the "Before Submit" event, "item_id" is available only on edit screens, indicating the item being edited. In the "After Submit" event, it refers to the edited item or a new item just created.
    • form_values: The collection of submitted form values.
  • To halt form submission in the "Before Submit" event due to validation failures, simply use a return statement with an appropriate error message, like so: return "Error Message". The error message must have a value and it must not be "" or null.
  • Examples:

    • Email Address Validation (Before Submit): Ensure the "email_address" field contains a valid email.
      if (!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/", form_values["email"], $matches)) {    
          return "Invalid Email Address";
      }
    • Populating Hidden Field (Before Submit): Populate a hidden field with a previously saved value.
      form_values["hidden-field"] = my_variables["previously-saved-value"];
    • Saving Newly Created Item ID (After Submit): Track the ID of a newly added item.
      my_variables["new_item_id"] = item_id;
    • Storing User Input for Later Use (After Submit): Retain input for subsequent processes.
      my_variables["name"] = form_values["name"];
    • Redirecting Based on Input (After Submit): Navigate to a different screen based on user input.
      if (form_values["category"] == "Sales") {    
          goto_screen("sales_dashboard");
      }

Love using ProcFu Guide?

Share your testimonial and let us know how ProcFu has helped you.

Share Your Testimonial

Built with ❤️ by Thaha for the Community