Specifics on how to get a date to appear in a box...

Insert a date into a database field with a compound name in ChronoForms.

Overview

The issue occurs because the PHP syntax for accessing a sub-array field in the form data is incorrect.
Use the correct array syntax to set the date value for the nested field, ensuring the data is properly saved to the database.

Answered
ar arrick 02 Apr, 2015
I have searched the forums for an answer to this, but I am unable to figure out exactly what I need to do to accomplish my needs...

I have a chronoform that has a connection action to my table...

In that table, I have put in a text field with the field name of "reviewedOn" and I have successfully utilized the following code in a custom code box above the render html action on the setup page to insert a date into a text field...


<?php
if ( !isset($form->data['reveiwedOn']) || !$form->data['reviewedOn'] ) {
  $form->data['reviewedOn'] = date('Y-m-d');
}
?>


However, the form is a connectivity form, so in order for that date to be saved to the database table, it needs to insert into a field labeled "dvopid[reviewedOn]".

It is at this point that I need help, nothing that I do saves this into the database, so I know there is some trick to this.

I have even tried setting it like this:

<?php
if ( !isset($form->data['dvopid[reveiwedOn]']) || !$form->data['dvopid[reviewedOn]'] ) {
  $form->data['dvopid[reviewedOn]'] = date('Y-m-d');
}
?>


and it doesnt change the field (even when I change the field name to "dvopid[reviewedOn]"
Gr GreyHead 03 Apr, 2015
Answer
1 Likes
Hi moorear,

The PHP syntax for a sub-array is $form->data['dvopid']['reviewedOn'] and not $form->data['dvopid[reviewedOn]']

I think that will work correctly.

Bob
ar arrick 03 Apr, 2015
That works now, thank you.
This topic is locked and no more replies can be posted.