Skip to content

Instantly share code, notes, and snippets.

@ash-f
ash-f / fluent-forms-birthdate-calc.js
Created September 5, 2022 21:08
fluent-forms-birthdate-calc
function calcAge($dob,$age){
$dob.on('change', function() {
var dobary = $(this).val().split('/');
var dobobj = new Date(dobary[2], dobary[0]-1, dobary[1]), birthday = { year: dobobj.getFullYear(), month: dobobj.getMonth(), date: dobobj.getDate() };
var todayobj = new Date(), thisyear = todayobj.getFullYear();
var thisYearsBirthday = new Date(thisyear, birthday.month-1, birthday.date);
var age = thisyear - birthday.year;
if(todayobj < thisYearsBirthday){ age--; }
$age.val(age);
@ash-f
ash-f / fluent-forms-month-year-field.php
Created October 12, 2021 07:49
WP Fluent Forms Month & Year field
// this converts Simple Text field to month & year field. change month_year to acctual field name.
function ff_month_year_field( $data, $form ){
if( $data['attributes']['name'] === 'month_year' ){
$data['attributes']['type'] = 'month';
}
return $data;
}
add_filter( 'fluentform_rendering_field_data_input_text', 'ff_month_year_field', 10, 2 );
@ash-f
ash-f / fluent-forms-custom-address-format.php
Created October 12, 2021 07:39
WP Fluent Forms custom address format
function ff_address_custom_format( $data, $form ){
$fields = $data['fields'];
// change the order of array below for your country
$data['fields'] = array(
'country' => $fields['country'],
'zip' => $fields['zip'],
'state' => $fields['state'],
'city' => $fields['city'],
'address_line_1' => $fields['address_line_1'],
'address_line_2' => $fields['address_line_2']
@ash-f
ash-f / fluent-forms-autocomplete-prevent-filter.php
Last active October 12, 2021 07:50
WP Fluent Forms autocomplete prevention
// Change field_name to actual field name.
function ff_avoid_autocomplete( $data, $form ){
if( $data['attributes']['name'] === 'field_name' ){
$data['attributes']['autocomplete'] = 'new-password';
}
return $data;
}
add_filter( 'fluentform_rendering_field_data_input_text', 'ff_avoid_autocomplete', 10, 2 );
@ash-f
ash-f / fluent-forms-address-state-selector.php
Last active January 11, 2023 16:42
WP Fluent Forms US state selector with Address field
function ff_address_add_datalist_attr( $data, $form ){
if( $data['attributes']['name'] == 'address[state]' ){
$data['attributes']['list'] = 'state-list';
}
return $data;
}
add_filter( 'fluentform_rendering_field_data_input_text', 'ff_address_add_datalist_attr', 10, 2 );
function ff_add_state_datalist( $html, $data, $form ){
if ( $data['attributes']['name'] === 'address[state]' ){
@ash-f
ash-f / fluent-forms-datepicker-default-date-configuration.js
Last active October 18, 2021 04:19
WP Fluent Forms date field advanced date configuration for changing default datepicker date
/* Enter this configuration to Advanced Date Configuration of Date field. change 01/01/1950 to any date. the date is US format. */
{
onOpen: [function(selectedDates, dateStr, instance){
if (dateStr == '') {
instance.jumpToDate('01/01/1950', false);
}
}],
/* Set minimum age.(= 18) delete if you don't limit the age */
maxDate: (new Date().getMonth() + 1) + "/" + new Date().getDate() + "/" + (new Date().getFullYear() - 18)
}
@ash-f
ash-f / fluent-forms-checkbox-key-value-swap-filter.php
Last active October 12, 2021 07:26
WP Fluent Forms checkbox key-value swapping filter
add_filter('fluentform_response_render_input_checkbox', function ($value, $field, $formId, $isHtml) {
if ( $formId === 3 ) {
$value='';
foreach ( $field['raw']['settings']['advanced_options'] as $fv ) {
$value .= '<li>' . $fv['value'] . '</li>';
}
if( $value !== '' ){
$value = '<ul style="white-space: normal;">' . $value . '</ul>';
}
}