diff --git a/includes/class-formidable.php b/includes/class-formidable.php index 49508f2..ce160f4 100644 --- a/includes/class-formidable.php +++ b/includes/class-formidable.php @@ -162,6 +162,9 @@ class DDHH_JM_Formidable { // Hook into Formidable form submission add_action( 'frm_after_create_entry', array( __CLASS__, 'handle_registration_submission' ), 30, 2 ); + // Add filter to set redirect URL in form response + add_filter( 'frm_json_response', array( __CLASS__, 'set_registration_redirect' ), 10, 1 ); + // Hook into Formidable form validation for ownership check add_filter( 'frm_validate_entry', array( __CLASS__, 'validate_job_ownership' ), 10, 2 ); add_filter( 'frm_validate_entry', array( __CLASS__, 'validate_job_deactivation_ownership' ), 10, 2 ); @@ -262,6 +265,36 @@ class DDHH_JM_Formidable { } } + /** + * Set redirect URL in form response for registration form + * + * @param array $response JSON response from form submission. + * @return array Modified response. + */ + public static function set_registration_redirect( $response ) { + // Only modify response if there's a form_id in the response + if ( ! isset( $response['form_id'] ) ) { + return $response; + } + + // Check if this is the registration form + if ( $response['form_id'] != self::get_registration_form_id() ) { + return $response; + } + + // Only redirect if the submission was successful (no errors) + if ( ! empty( $response['errors'] ) ) { + return $response; + } + + error_log('DDHH Registration: Setting redirect in form response'); + + // Set redirect URL + $response['redirect_url'] = home_url( '/anbieter-dashboard/' ); + + return $response; + } + /** * Handle registration form submission *