fix(07-01): add JavaScript redirect for registration form
- Added add_registration_redirect_script() method - Listens for frmFormComplete event on registration form - Redirects to /anbieter-dashboard/ after 1.5s delay - Shows success message before redirect - Replaces non-working frm_json_response filter approach
This commit is contained in:
@@ -162,8 +162,8 @@ class DDHH_JM_Formidable {
|
|||||||
// Hook into Formidable form submission
|
// Hook into Formidable form submission
|
||||||
add_action( 'frm_after_create_entry', array( __CLASS__, 'handle_registration_submission' ), 30, 2 );
|
add_action( 'frm_after_create_entry', array( __CLASS__, 'handle_registration_submission' ), 30, 2 );
|
||||||
|
|
||||||
// Add filter to set redirect URL in form response
|
// Add JavaScript redirect for registration form
|
||||||
add_filter( 'frm_json_response', array( __CLASS__, 'set_registration_redirect' ), 10, 1 );
|
add_action( 'wp_footer', array( __CLASS__, 'add_registration_redirect_script' ) );
|
||||||
|
|
||||||
// Hook into Formidable form validation for ownership check
|
// 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_ownership' ), 10, 2 );
|
||||||
@@ -266,33 +266,37 @@ class DDHH_JM_Formidable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set redirect URL in form response for registration form
|
* Add JavaScript to redirect after successful registration
|
||||||
*
|
|
||||||
* @param array $response JSON response from form submission.
|
|
||||||
* @return array Modified response.
|
|
||||||
*/
|
*/
|
||||||
public static function set_registration_redirect( $response ) {
|
public static function add_registration_redirect_script() {
|
||||||
// Only modify response if there's a form_id in the response
|
// Only add on login page
|
||||||
if ( ! isset( $response['form_id'] ) ) {
|
if ( ! is_page( 'anbieter-login' ) ) {
|
||||||
return $response;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is the registration form
|
$form_id = self::get_registration_form_id();
|
||||||
if ( $response['form_id'] != self::get_registration_form_id() ) {
|
$redirect_url = home_url( '/anbieter-dashboard/' );
|
||||||
return $response;
|
|
||||||
|
if ( ! $form_id ) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
// Only redirect if the submission was successful (no errors)
|
<script type="text/javascript">
|
||||||
if ( ! empty( $response['errors'] ) ) {
|
jQuery(document).ready(function($) {
|
||||||
return $response;
|
// Listen for Formidable form submission success
|
||||||
}
|
$(document).on('frmFormComplete', function(event, form, response) {
|
||||||
|
// Check if this is the registration form
|
||||||
error_log('DDHH Registration: Setting redirect in form response');
|
if (form.attr('id') === 'form_provider_registration' ||
|
||||||
|
form.find('input[name="form_id"]').val() == '<?php echo esc_js( $form_id ); ?>') {
|
||||||
// Set redirect URL
|
// Redirect after a short delay to show success message
|
||||||
$response['redirect_url'] = home_url( '/anbieter-dashboard/' );
|
setTimeout(function() {
|
||||||
|
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
||||||
return $response;
|
}, 1500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user