The 1.9.2 seems broken to get fields value with bricksforge 1.0.8
[13-Oct-2023 19:57:50 UTC] PHP Warning: Undefined array key "fields" in /home/xxx/wp-content/themes/bricks/includes/integrations/form/init.php on line 205
[13-Oct-2023 19:57:50 UTC] PHP Warning: foreach() argument must be of type array|object, null given in /home/xxx/wp-content/themes/bricks/includes/integrations/form/init.php on line 205
function test_form($form)
{
$fields = $form->get_fields();
$formId = $fields["formId"];
if ($formId !== "slxrsx") {
return;
}
// Correct the array index to access form fields
$email_value = $fields["form-field-email"];
$name_value = $fields["form-field-nom"];
$message_value = $fields["form-field-message"];
//$user_id = get_current_user_id();
$pdo = new PDO(
"mysql:host=" . DBIN_HOST . ";dbname=" . DBIN_NAME,
DBIN_USER,
DBIN_PASS
);
$sql =
"INSERT INTO test (email, nom, message) VALUES (:email, :nom, :message)";
$stmt = $pdo->prepare($sql);
// Bind parameters correctly
$stmt->bindParam(":email", $email_value, PDO::PARAM_STR);
$stmt->bindParam(":nom", $name_value, PDO::PARAM_STR);
$stmt->bindParam(":message", $message_value, PDO::PARAM_STR);
$stmt->execute();
$template_id = "9c60f8d1-0bfc-bd7f-73ff-8c71da452ceb";
$to = "xxxx";
$subject = "Hello World";
$message = $message_value;
$headers = [];
$attachments = [];
bricksforge_send_mail(
$template_id,
$to,
$subject,
$message,
$headers,
$attachments
);
}
add_action("bricks/form/custom_action", "test_form", 10, 1);
They update lots of things (good things !)
By the way, We cannot register with only email (in form), but seems to be vanilla Bricks bug (w/ woocommerce) : Bug report Bricks Builder Forum