Reference other field values in module form

I’m creating a custom field in a module where I would like to set the value as the timestamp of two other fields (a date and time) using strtotime. Is there a way to reference the value of these other fields inside of the settings form array?

Hi Josh,

What module file are you trying to do this in? Also, are you trying to set that value after a user changes the value or as the default?

Justin

This is a custom module, one for upcoming event date, time etc.

Short story:

I’d like the value of this field to be updated once the hits save on the module settings form – hopefully I don’t need to use js instead.

Long story:

We’ve created a custom field to save module field values as post_meta, and that’s been working great. The custom field loops through an array we supply and creates a hidden with the field names to save. The problem is it simply saves the values that are stored in _fl_builder_data, and instead I need to combine 2 field values inside of a strtotime and save that as post_meta. We’d like to keep our custom field as flexible as possible, so being able to pass key=>val pairs is ideal.

Hi Josh,

Thanks for the additional info. Have you looked at the module update method that you can override? That runs each time a module is saved and is passed the settings before they are saved to the database so you can modify them. Here’s an example…

public function update( $settings ) {
    $settings->my_datetime = time();
    return $settings;
}

Let me know if that helps.

Justin

Yes I was leaning toward using that in this case but I figured I would ask if there was a different method :slight_smile: Thanks.

Yep, that should do the trick! There may be other ways, but that’s probably the easiest :slight_smile:

Justin

Now you’ve got me curious…Ideally I’d like to not use the update function and just use our custom field. If you can think of an alternative inside the form array let me know

After a bit more research I’ve found that $settings is out of scope of the fl_builder_control_ action, however it is in scope when the fields are included as a file. Any idea of how to make $settings global? From there I should be able to grab the values of the other fields…

Hey Josh,

The $settings object isn’t available in the fl_builder_control_ action. Can you tell me how you’re trying to access it?

Justin

Got it figured out, thanks