Last active
April 30, 2021 00:40
-
-
Save mishterk/50a441c4d44504d649e3f31ccfd579ce to your computer and use it in GitHub Desktop.
AJAX functionality examples for Advanced Forms Pro version 1.8.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function ($) { | |
// Changing the response type to a redirect on the fly. | |
acf.addAction('af/form/ajax/submission', function (data, form) { | |
if (form.key === 'form_5f8f987654e0') { | |
data.type = 'redirect'; | |
data.redirect_url = 'https://example.com'; | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function ($) { | |
// Changing the success message. | |
acf.addAction('af/form/ajax/submission', function (data, form) { | |
if (form.key === 'form_5f8f987654e0') { | |
data.success_message = '<div style="background:green; color:white;">This is a new message!</div>' | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
advanced_form( 'form_5f8f987654e0', [ 'ajax' => true ]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'af/form/ajax/response', function ( $response, $form, $args ) { | |
if ( $form['key'] === 'form_5f8f987654e0' ) { | |
// If our 'star_rating' ACF field has a value less than 3, redirect | |
// the user to another page. | |
if ( af_get_field( 'star_rating' ) < 3 ) { | |
$response['type'] = 'redirect'; | |
$response['redirect_url'] = 'https://example.com'; | |
} | |
} | |
return $response; | |
}, 10, 3 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function ($) { | |
// Triggering any custom JavaScript. | |
acf.addAction('af/form/ajax/submission', function (data, form) { | |
if (form.key === 'form_5f8f987654e0') { | |
// …add custom handler code here… | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment