I am needing to have a custom element that will look at a drop-down called month and conditionally insert the numeric month into the database. For example if the user selects October it would put the number 10 in the numeric_month field in the DB. The month drop-down is set to another field in the same database and unfortunately there is no way to combine them for our purposes. Any help would be appreciated. I am new to php coding.
Asked
Active
Viewed 3,095 times
1 Answers
1
- Create a hidden field in your form for
numeric_month
- add a "Custom Code" action to the "On Submit" event before your "DB Save Action"
In the Custom Code action insert PHP code to set the numeric_month
field to the appropriate value depending on the selected drop down value.
In ChronoForms v4 or v5, this will be something similar to this:
<?php
$form->data['numeric_month'] = date("n",strtotime($form->data['month']));
?>
This would set numeric_month
to '7' for a month
value of 'July'.
Use date("m",strtotime($form->data['month'])
to set numeric_month
to '07' instead.
For more information about the PHP code to convert a month name to a numberic string, see the answers to these questions:

Community
- 1
- 1

Neil Robertson
- 3,295
- 3
- 28
- 49