Support

Account

Home Forums General Issues Duplicate forms: Handling submission

Unread

Duplicate forms: Handling submission

  • Hello everyone!

    I’m trying to create sort of “links” between WooCommerce order items and a custom field group at checkout time. The idea is to assign a field group “Entity” to a specific item in the order, so we can individualize the checkout process.

    I already went ahead and created the groups and forms for the Entity, it contains a name, birthdate and address. I also managed to render the form next to each product item, by iterating over the cart and calling the form via acfe_form(...).

    My issue is that I am unsure of how to access the individual forms upon submission. As far as I can see, fields are submit by their name property (or the key?), and there’s no way to customize how the POST body will look. This would not be an issue for single cart items, since then there would be no key duplicates, but if a form is rendered for every cart item then there will be duplicate names on the HTML input elements, which I’m pretty sure is not allowed.

    Previously we were using a repeater with the fields for the Entity mentioned above, but that didn’t really allow to visually link a product preview to each item in the repeater for the user. The goal is to show each Entity form input in a seperate table cell, inside the larger table representing the cart.

    Something that I attempted was to modify the name of the form field using the load_field filter. The idea was to postfix each field with the index of the item in the cart, so the input fields can be differentiated at submission time. It would not matter that this “breaks” the intended workflow, since the values can be handled by us inside the submission callback.

    function postfix_product_index ( $field ) {
    global $checkout_product_index;
    if ( $checkout_product_index != NULL ) {
    $field[‘name’] .= ‘_’ . $checkout_product_index;
    }
    return $field;
    }

    However, it does not seem like you can modify the name property like this.

    I’d be glad to give more input on this if I left something unclear.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.