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
|
||||
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 );
|
||||
// Add JavaScript redirect for registration form
|
||||
add_action( 'wp_footer', array( __CLASS__, 'add_registration_redirect_script' ) );
|
||||
|
||||
// Hook into Formidable form validation for ownership check
|
||||
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
|
||||
*
|
||||
* @param array $response JSON response from form submission.
|
||||
* @return array Modified response.
|
||||
* Add JavaScript to redirect after successful registration
|
||||
*/
|
||||
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;
|
||||
public static function add_registration_redirect_script() {
|
||||
// Only add on login page
|
||||
if ( ! is_page( 'anbieter-login' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this is the registration form
|
||||
if ( $response['form_id'] != self::get_registration_form_id() ) {
|
||||
return $response;
|
||||
$form_id = self::get_registration_form_id();
|
||||
$redirect_url = home_url( '/anbieter-dashboard/' );
|
||||
|
||||
if ( ! $form_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($) {
|
||||
// Listen for Formidable form submission success
|
||||
$(document).on('frmFormComplete', function(event, form, response) {
|
||||
// Check if this is the registration form
|
||||
if (form.attr('id') === 'form_provider_registration' ||
|
||||
form.find('input[name="form_id"]').val() == '<?php echo esc_js( $form_id ); ?>') {
|
||||
// Redirect after a short delay to show success message
|
||||
setTimeout(function() {
|
||||
window.location.href = '<?php echo esc_js( $redirect_url ); ?>';
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user