Table of Contents:

TOC

Echo PHP Functions In Bricks Forge Pro Forms: Create Programmatic Default Values For Form Fields

Introduction

When working with Pro Forms, I often like to set a default value for a field. And you can set just about anything you want as a default value!

That means, you can store text, numbers, urls…and echo PHP functions.

Yes, you read that right! You can echo PHP functions in the Value parameter of Pro Forms fields!

Don’t have Bricks Forge Yet?

Get Bricks Forge Today!

Set a Default Value For a Date Field

I wanted to set a default value for a date field. The default value would be the current date and time based on in the WordPress time settings you setup in the WP admin.

All you have to do it add the two functions below to your functions.php file.
The first function is from the Bricks code review system inside the Bricks settings in WP admin. If you don’t whitelist the your functions, you can’t call them inside an echo tag. The second function gets the date and time from the WP settings and formats it for the Bricks Forge date field.

//whitelist the get_wp_time function brick - code review 
add_filter( 'bricks/code/echo_function_names', function() {
  return [
	'get_wp_time'  
  ];
} );

//get the current type in a Bricks Forge date field friendly format.
function get_wp_time(){
    $timezone = get_option('timezone_string'); // Fetch WP timezone
    if (!$timezone) {
        $timezone = 'America/New_York'; // Fallback in case no timezone is set
    }

    $datetime = new DateTime('now', new DateTimeZone($timezone));
    return $datetime->format('F j, Y H:i'); // Format as "January 1, 2025 19:25"
}

To set the default value, go to the general tab of your date field and insert this:

echo:get_wp_time() - MAKE SURE TO ADD CURLY BRACKETS {} SEE IMAGE BELOW
Image

That’s it! Now the form will set the current WordPress date and time inside the field!

Need Help With Bricks Builder?

John the owner of Bricks Coach and the lead instructor.
Book a consultation

Related Posts

Bricks Forge Pro Form Field Validation Rules: No Spaces Or Capital Letters

February 13, 2025

Review Your Cart
0
Add Coupon Code
Subtotal