Trongate Website Homepage

Posting Additional Parameters

The mx-vals attribute in Trongate MX allows you to attach additional values to your HTTP requests as if they were submitted as part of an ordinary HTML form. This feature is particularly useful for dynamically adding data to your requests without modifying the form structure.

Syntax

<element mx-vals='{
    "key1": "value1",
    "key2": "value2"
}'></element>

The mx-vals attribute should contain a JSON object, where each key-value pair represents a form field and its value.

Usage

To use the mx-vals attribute:

  1. Add the attribute to an element that triggers an AJAX request (e.g., a button with mx-post, mx-put, or mx-patch).
  2. Specify the additional form fields in a JSON object format.

Example

<form mx-post="trongate_pages/add_headline" 
      mx-vals='{
          "last_name": "Doe",
          "age": 30
      }'>
    <input type="text" name="first_name">
    <button type="submit">Submit</button>
</form>

In this example:

  1. Security: Always follow best practices for securing your API endpoints when using mx-vals. For more information, see Securing Endpoints With Trongate MX.
  2. Consistency: Ensure the keys in mx-vals match the expected field names on the server side.
  3. Validation: Validate the additional data on the server side to ensure it meets your application's requirements.

Additional Information

  • The mx-vals attribute should contain a valid JSON object. Each key-value pair represents a form field and its value.
  • Ensure that the JSON string is properly formatted to avoid parsing errors.
  • The values specified in mx-vals will be added to the HTTP request along with any existing form fields.
  • The mx-vals attribute works with POST, PUT, and PATCH requests. It does not apply to GET requests.

Additional Notes

By utilizing the mx-vals attribute, you can enhance the flexibility and control of your HTTP requests in Trongate MX, making it easier to manage additional form values and improve the robustness of your web applications.