', $markup );
}
/**
* Whether this field expects an array during submission.
*
* @since 2.4
*
* @return bool
*/
public function is_value_submission_array() {
return true;
}
/**
* Determines if any of the submission values are empty.
*
* @since Unknown
* @access public
*
* @used-by GFFormDisplay::is_empty()
*
* @param int $form_id The form ID.
*
* @return bool True if empty. False otherwise.
*/
public function is_value_submission_empty( $form_id ) {
$value = rgpost( 'input_' . $this->id );
if ( is_array( $value ) ) {
// If some but not all inputs are empty, return false so that this field's validation method will be triggered.
return empty( array_filter( $value ) );
} else {
return strlen( trim( $value ) ) <= 0;
}
}
/**
* Determines whether the given value is considered empty for this field.
*
* @since 2.4
*
* @param string|array $value The value.
*
* @return bool True if empty. False otherwise.
*/
public function is_value_empty( $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $input ) {
if ( strlen( trim( $input ) ) <= 0 ) {
return true;
}
}
return false;
} else {
return strlen( trim( $value ) ) <= 0;
}
}
/**
* Prepares the field value to be saved after an entry is submitted.
*
* @since Unknown
* @access public
*
* @used-by GFFormsModel::prepare_value()
*
* @param string $value The value to prepare.
* @param array $form The Form Object. Not used.
* @param string $input_name The name of the input. Not used.
* @param int $lead_id The entry ID. Not used.
* @param array $lead The Entry Object. Not used.
*
* @return array|string The field value, prepared and stripped of tags.
*/
public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) {
if ( empty( $value ) && ! is_array( $value ) ) {
return '';
}
// If $value is a default value and also an array, it will be an associative array; to be safe, let's convert all array $value to numeric.
if ( is_array( $value ) ) {
$value = array_values( $value );
}
if ( ! is_array( $value ) && ! empty( $value ) ) {
preg_match( '/^(\d*):(\d*) ?(.*)$/', $value, $matches );
$value = array();
$value[0] = $matches[1];
$value[1] = $matches[2];
$value[2] = rgar( $matches, 3 );
}
$hour = wp_strip_all_tags( $value[0] );
$minute = wp_strip_all_tags( $value[1] );
$ampm = wp_strip_all_tags( rgar( $value, 2 ) );
if ( ! empty( $ampm ) ) {
$ampm = " $ampm";
}
if ( ! ( rgblank( $hour ) && rgblank( $minute ) ) ) {
$value = sprintf( '%02d:%02d%s', $hour, $minute, $ampm );
} else {
$value = '';
}
return $value;
}
/**
* Returns a JS script to be rendered in the front end of the form.
*
* @param array $form The Form Object
*
* @return string Returns a JS script to be processed in the front end.
*/
public function get_form_inline_script_on_page_render( $form ) {
//Only return merge tag script if form supports JS merge tags
if ( ! GFFormDisplay::has_js_merge_tag( $form ) ) {
return '';
}
return "gform.addFilter( 'gform_value_merge_tag_{$form['id']}_{$this->id}', function( value, input, modifier ) { if( modifier === 'label' ) { return false; } var ampm = input.length == 3 ? ' ' + jQuery(input[2]).val() : ''; return jQuery(input[0]).val() + ':' + jQuery(input[1]).val() + ' ' + ampm; } );";
}
/**
* Overrides GF_Field to prevent the standard input ID from being used.
*
* @since Unknown
* @access public
*
* @return null
*/
public function get_entry_inputs() {
return null;
}
/**
* Removes the "for" attribute in the field label. Inputs are only allowed one label (a11y) and the inputs already have labels.
*
* @since 2.4
* @access public
*
* @param array $form The Form Object currently being processed.
*
* @return string
*/
public function get_first_input_id( $form ) {
return '';
}
/**
* Sanitizes settings for the Time field.
*
* @since Unknown
* @access public
*
* @used-by GFFormDetail::add_field()
* @used-by GFFormsModel::sanitize_settings()
* @uses GF_Field::sanitize_settings
* @uses GF_Field_Time::$timeFormat
*
* @return void
*/
public function sanitize_settings() {
parent::sanitize_settings();
if ( ! $this->timeFormat || ! in_array( $this->timeFormat, array( 12, 24 ) ) ) {
$this->timeFormat = '12';
}
}
}
// Register the Time field with the field framework.
GF_Fields::register( new GF_Field_Time() );