Form styling options for ACF forms
Mike Smith
I prefer to use BD forms for ACF work and create a custom hook instead. Given that code is required either way, I don't see the need for this element.
Pedro Cassian
Mike Smith by any chance do you know where I can find a tutorial to create a custom web hook for acf? No idea how to do that
Mike Smith
Pedro Cassian It's linked on the BD help pages, but here:
https://github.com/soflyy/breakdance-developer-docs/blob/master/form-actions/readme.md
Mike Smith
Pedro Cassian Here's a function I made that updates the user profile... in case a working example helps :)
// Define the custom action class for updating user profiles
class UpdateUserProfileAction extends \Breakdance\Forms\Actions\Action {
public static function name() {
return 'Update User Profile';
}
public static function slug() {
return 'update_user_profile';
}
public function run($form, $settings, $extra) {
// Check if the user is logged in
if (!is_user_logged_in()) {
return ['type' => 'error', 'message' => 'Not logged in'];
}
// Get the current user ID
$user_id = get_current_user_id();
// Get the form data from $extra['fields']
$acc_sc = isset($extra['fields']['acc_sc']) ? sanitize_text_field($extra['fields']['acc_sc']) : '';
$acc_ac = isset($extra['fields']['acc_ac']) ? sanitize_text_field($extra['fields']['acc_ac']) : '';
$acc_bn = isset($extra['fields']['acc_bn']) ? sanitize_text_field($extra['fields']['acc_bn']) : '';
$acc_ah = isset($extra['fields']['acc_ah']) ? sanitize_text_field($extra['fields']['acc_ah']) : '';
// Update the user meta fields
update_user_meta($user_id, 'acc_sc', $acc_sc);
update_user_meta($user_id, 'acc_ac', $acc_ac);
update_user_meta($user_id, 'acc_bn', $acc_bn);
update_user_meta($user_id, 'acc_ah', $acc_ah);
return ['type' => 'success', 'message' => 'Details Updated'];
}
}
// Register the custom action in Breakdance
add_action('init', function() {
// Fail if Breakdance is not installed and available
if (!function_exists('\Breakdance\Forms\Actions\registerAction') || !class_exists('\Breakdance\Forms\Actions\Action')) {
return;
}
\Breakdance\Forms\Actions\registerAction(new UpdateUserProfileAction());
});
Pedro Cassian
Mike Smith thanks! Will play around with it today!