Forums

Set form values using PHP

momentis 14 Feb, 2018
In prior versions of CF, I would use PHP code like below in a Custom Code action to set values when a form was opened:
<?php
$today = date("Y-m-d h:i:s");
$form->data['pr_datestamp'] = $today;
$thisdate = date("m/d/Y");
$form->data['pr_date'] = $thisdate;
$form->data['pr_ip'] = $_SERVER['REMOTE_ADDR'];
?>
Using CFv6, I am completely confused how to do something similar. I have the documentation, but I am ashamed to admit that I cannot figure out how to do what I want.

Can anyone point me to something that could explain this to me?

Rick
GreyHead 15 Feb, 2018
Hi Rick,

The code you need for CFv6 has changed - you can see examples at the foot of Page 34 of the manual.

Bob
momentis 15 Feb, 2018
Bob,

I did look at that page. I am just really not sure how to use it. It's embarrassing, but true.

Rick
GreyHead 16 Feb, 2018
Hi Rick,

I think you need something like this:
$this->data('pr_datestamp', date("Y-m-d h:i:s"), true);
$this->data('pr_date', date("m/d/Y"), true);
$this->data('pr_ip', $_SERVER['REMOTE_ADDR'], true);
Bob
This topic is locked and no more replies can be posted.