Conditional Calculation

I am registering students for a class, and would like to pass them on to Paypal after they complete the registration form to pay the tuition.  The thing is we are offering an early registration discount.  So somewhere on the form I would like a variable to be created, say EarlyReg, that is 1 if [date] is on or before my early registration date, and 0 if it is after.  Then I would like to call this variable in the calculation portion of a read-only field that outputs a number equal to: #ofStudents*15*EarlyReg.

I don’t know anything about coding althought I frequently have Excel do this kind of automation.  I read about adding this calculation into the before or after fields of the HTML editor and have been reading about javascript, but since I don’t have any experience coding, don’t really know how to write what I want, and more importantly, if I could get the javascript to work, I don’t understand how to be able to call the EarlyReg value in the calculation portion of a form field.

I think my if statement would look something like this:

var EarlyReg=0

if [date]<=date(2012,11,30,23,59,59)

{EarlyReg=1}

Else {}

Any help will be greatly appreciated, especially if someone could provide the code that I should put in the before or after fields of the HTML editor and tell me what to call in the calculation field.

Thanks,

Annette

This might be easiest to use the built-in calculations, and then change the 1 or 0 with the default value hook in php. You can add a hidden field for the early registration with a default value of 0. Here's an example you could use in your theme functions.php or a new plugin to change the 0 to 1 depending on the date. The date part may need some tweaking if you'd like to change the timezone you're using.

add_filter('frm_get_default_value', 'my_custom_default_value', 10, 2);
function my_custom_default_value($new_value, $field){
  if($field->id == 25 and (strtotime('2012-11-30 23:59:59') > time())){ //change 25 to the ID of the field
    $new_value = '1';
  }
  return $new_value;
}

Hi Stephanie,

Thanks for the response.  I think I'm in over my head, and will just settle for a less elegant solution that I understand :).

Appreciate the prompt feedback.

Annette

Topic closed.