Hooking to form data on redirect location in form element

Been asked several times, but we need a bricks admin to chime in here. How do we hook into the value of a form’s field data for use in a URL parameter in the Redirect location for a form submit?

1 Like

Bump. A redirect like

www.google.com/?param={{field_id}}

doesnt work.

1 Like

Hey @Wingtracer,

you can use a custom action for this. Please have a look at this example in the academy.

Your custom action could look something like this:

add_filter( 'bricks/form/custom_action', function( $form ) {
    $form_fields = $form->get_fields();
    $form_id = $form_fields['formId'];
    
    if ( $form_id !== 'oqmkku' ) return;

    // The ID of the field you want to use as a URL param
    $field_id = '690ae6';
    
    $param = isset( $form_fields['form-field-' . $field_id] ) ? $form_fields['form-field-' . $field_id] : '';
    
    if ( $param ) {
        // The URL you wanna redirect to
        $redirect_to = 'https://bricksbuilder.io/?param=' . $param;
        
        $form->set_result( [
            'action' => 'my_custom_redirect',
            'type' => 'redirect',
            'redirectTo' => $redirect_to,
            'redirectTimeout' => 0
        ] );
    }

    return $form;
} );

Let me know if that helps.

Best,

André

1 Like

Dear @aslotta ,

It worked to me once but I changed something and it is not working now. I don’t know why.
Could you make www.google.com/?param={{field_id}} working, please. That would be very nice.

Thank You,
Andrew