Buy Now
Sign in

Using switch to compare dates

stwgroup , April 05 2020, 02:04
S
stwgroup 19
April 05 2020, 02:04 #391900
I have a form with a start date and end date. How can I use the fn: switch in the event to verify the end date is later than the start date after submit button is clicked.
healyhatman 9
April 05 2020, 08:25 #391901
Use PHP instead.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
S
stwgroup 19
April 05 2020, 14:05 #391904
Great Thanks.. I have the following in a Logic PHP pasing the N or Y:

//php_check_add_dates
// Declare two dates
// initialize it
$date1 = $this->data("start_date");
$date2 = $this->data("end_date");

// Use comparison operator to
// compare dates
if ($date1 < $date2)
$timeoff_pass="Y";
else
$timeoff_pass="N";

return $timeoff_pass;
I am having trouble with the switch.
the debug output is as follows:
[php_check_add_dates] => Array
(
[returned] => Y
[var] => Y
)

[sw_check_add_dates] => Array
(
[finished] => 1
[var] =>
)
My switch is:
data provider: {var:php_check_add_dates.timeoff_pass}
Values Setup:
N:{error: End Date cannot be prior to Start Date}
Y:{redirect:index}
I have tried different data providers with no success..
teldrive 636
August 07 2021, 20:45 #396919
 Answer
I hope this trick can helps, in CCv6 enviroment:
i am not sure if I can call to one {view:function} from php code, so my only chance is I have to use switch function, the issue is that I need to do some php process with row values of a table_list and generate a new row value( not sure if I can save it in some way), for example
model.new_field={fn:field1_minus_field2}
-----------------------------------------------------------------in php function with name field1_minus_field2 I have:
field1=$this->get('table_list.row.model.field1');
field2=$this->get('table_list.row.model.field2');
echo field1-field2;
but after this operation I still need to use the "new_field" in order to view a button when is different than "0" (meaning: only when there are vacancies users can register)
so after some research I get sucess using a trick inside swith function
My new column is model.register:{fn:sw_button}
-------------------------------------------------------------------------I made a new php function compare_field1_and_field2
field1=$this->get('table_list.row.model.field1');
field2=$this->get('table_list.row.model.field2');
final= field1-field2;
return ($final ==0 ? 1: 0);
---------------------------------------------------------------------in my function sw_button
and now is the trick, in switch data provider i used this: {fn:compare_field1_and_field2}{var:compare_field1_and_field2}
and in values setup
1:FULL
0:{view:registro_button}
not sure if I can do it by other method, anyway I hope it helps because this works
Teldrive