• Resolved delanthear

    (@delanthear)


    Hi,

    Might be beyond the scope of support, but it might be easy!

    I’ve written some code which hooks forminator_form_after_handle_submit. When a form is submitted, I’m grabbing the data from $POST[] and creating a woocommerce product from the data. That all works fine, but I want to return back the slug of the product I’ve just created in one of the fields so I can use it in the email forminator sends.

    Is that possible? Is there a way to update the fields at this point? (I’ve specificaly added a hidden field to add this value in, so I can then output this into the html email for a link?)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter delanthear

    (@delanthear)

    oh, am I being dumb and I can just return back the array with the modification?

    EDIT: Nope, I suspect the data has all been captured by this point and the emails sent. I guess I need to use forminator_form_before_handle_submit

    • This reply was modified 11 months, 2 weeks ago by delanthear.
    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @delanthear

    I hope you are doing well today.

    I pinged our SLS Team to review your query. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter delanthear

    (@delanthear)

    That’s would be appreciated! I’m slightly out of my depth, which is annoying because getting the slug into the email is the LAST thing I need to do here!

    ??

    Thread Starter delanthear

    (@delanthear)

    If it’s useful, this is pretty much what I’m trying to do, but with Gravity Forms instead or Forminator: https://docs.gravityforms.com/gform_pre_submission/#2-populate-a-field-using-the-value-from-another-field Example 3.

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @delanthear,

    Could you please check and see whether the following hook helps?

    forminator_custom_form_submit_before_set_fields

    Where you can directly fetch data using it’s parameter?$field_data_array?instead of using $_POST and this will help in modifying the hidden field too.

    Please check this example code as reference:

    add_action('forminator_custom_form_submit_before_set_fields', 'forminator_append_email_to_hidden_field', 10, 3);
    
    function forminator_append_email_to_hidden_field($entry, $form_id, $field_data_array)
    {
    
         $form_ids = array(6); // Please change the form ID.
        
        if (!in_array($form_id, $form_ids)) {
            return;
        }
    
        $user_email = '';
    
    
        foreach ($field_data_array as $key => $value) {
            if (strpos($value['name'], 'text-1') !== false) {
    
                if (is_email($value['value'])) {
                    //it is already an email no need to replace.
                    $user_email = $value['value'];
                } else {
                    //get the email by user login
                    $user_email = get_user_by('login', $value['value'])->user_email;
                }
            }
        }
    
    
        foreach ($field_data_array as $key => $value) {
            if (strpos($value['name'], 'hidden-1') !== false) {
                Forminator_CForm_Front_Action::$info['field_data_array'][$key]['value'] =  $user_email;
            }
        }
    }


    I hope the above helps in moving forward.

    Kind Regards,

    Nithin

    Thread Starter delanthear

    (@delanthear)

    Great! I’ll give that a go. Thanks!

    Thread Starter delanthear

    (@delanthear)

    Works! Thanks.

    • This reply was modified 11 months, 2 weeks ago by delanthear.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change a field during submission’ is closed to new replies.