Reputation: 31
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.
Upvotes: 2
Views: 3189
Reputation: 3345
numeric_month
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:
convert month from name to number
PHP convert short month-name to month-number
Upvotes: 1