I have found another way of handling setting a date and time field. What do I need to change in the lines:$receipt_name = JRequest::getString('receipt', 'No', 'post');JRequest::setVar('receipt', $receipt_name);for it to work in CFv4? I have a radio button control on my form where they select either "will mail", "is attached", or "none needed". If they select "is attached" the file name is saved as the "receipt" variable. The above two lines check to see if there is a value in "receipt" and if there's not, it uses the value "No". Then the value of receipt is referenced in the email that is sent.ThanksTami"> Help with change in PHP code from CFv3 to CFv4 - Forums

Forums

Help with change in PHP code from CFv3 to CFv4

Ravens 05 Sep, 2011
IN CFv3 I had the following code in the "on submit code - before sending email" field:
<?php
date_default_timezone_set('America/Chicago');
$receipt_name = JRequest::getString('receipt', 'No', 'post');
JRequest::setVar('receipt', $receipt_name);
$reqdate=date('F d, Y');
JRequest::setVar('reqdate',$reqdate);
$reqtime=date('g:i a');
JRequest::setVar('reqtime',$reqtime);

?>

I have found another way of handling setting a date and time field. What do I need to change in the lines:
$receipt_name = JRequest::getString('receipt', 'No', 'post');
JRequest::setVar('receipt', $receipt_name);

for it to work in CFv4? I have a radio button control on my form where they select either "will mail", "is attached", or "none needed". If they select "is attached" the file name is saved as the "receipt" variable. The above two lines check to see if there is a value in "receipt" and if there's not, it uses the value "No". Then the value of receipt is referenced in the email that is sent.

Thanks
Tami
GreyHead 05 Sep, 2011
Hi Tami,

ChronoForm v4 copies the form data into the $form->data array and uses that. The JRequest::get methods will still work for retrieving data (unless it has been changed in ChronoForms) but you must save new results in $form->data to make them available.
if ( !$form->data['receipt'] ) {
  $form->data['receipt'] = 'No';
}


Bob

PS The new ghost values in CFv4 RC2.0 allow you to set default values in the form elements.
Ravens 05 Sep, 2011
Ok, you've lost me on this one. What do I do with this code?
if ( !$form->data['receipt'] ) {
$form->data['receipt'] = 'No';
}

Do I still use my original code and add yours to it or does it replace it? Do I put it in a "custom code" event or a "JS Load" event?

Sorry for all the questions.
Tami
GreyHead 05 Sep, 2011
Hi Tami,

That code snippet replaces these lines in the code you posted.
$receipt_name = JRequest::getString('receipt', 'No', 'post');
JRequest::setVar('receipt', $receipt_name);

It can go in a Custom Code action - though best not in a JavsScript one.

Bob
Ravens 05 Sep, 2011
Ok, I've posted your code into a "custom code" event in the on-submit event. However, on my thanks page I'm getting the error,


Notice: Undefined index: receipt in E:\www\www.ravenbands.org\administrator\components\com_chronoforms\form_actions\custom_code\custom_code.php(18) : eval()'d code on line 2

What am I missing? Currently the "custom code" is after the "handle arrays" event. I don't know if that makes any difference.

Tami
GreyHead 05 Sep, 2011
Hi Tami,

Looks like there isn’t any 'receipt' input data coming from the form.

Bob
Ravens 05 Sep, 2011
Receipt is a hidden field. If the radio button "is attached" is selected then "receipt" becomes visible. That's why I was trying to set the value of it to no when it's not selected. I also tried using the "ghost" feature but can't get it to work either.
GreyHead 06 Sep, 2011
Hi Tami,

The easiest fix is to set Error Reporting to System Default or None in your site Global Information. This should hide the PHP Warning messages.

Otherwise you'll need to add an extra check in this code
if ( !isset($form->data['receipt']) || !$form->data['receipt'] ) {
  $form->data['receipt'] = 'No';
}
?>

Bob
This topic is locked and no more replies can be posted.