Buy Now
Sign in

Set form values using PHP

momentis , February 14 at 19:42
momentis
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
Hi Rick,
The code you need for CFv6 has changed - you can see examples at the foot of Page 34 of the manual.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
momentis
Bob,
I did look at that page. I am just really not sure how to use it. It's embarrassing, but true.
Rick
GreyHead
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
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much