array( __( 'First', '2ranq-forms' ), 'given-name' ), 'last' => array( __( 'Last', '2ranq-forms' ), 'family-name' ), ); } /** * The type. * * @return string */ public function get_type() { return 'name'; } /** * The name in the builder. * * @return string */ public function get_label() { return __( 'Name', '2ranq-forms' ); } /** * The icon. * * @return string */ public function get_icon() { return 'dashicons-admin-users'; } /** * The group. * * @return string */ public function get_group() { return 'fancy'; } /** * The name the value arrives under. This field sends an array. * * @param array $field The field settings. * * @return string */ protected function input_name( $field ) { return 'ranq_fields[' . $this->field_key( $field ) . ']'; } /** * Prints the field. Two inputs side by side, each with its own small label * underneath. * * @param array $field The field settings. * @param int $form_id The form id. * * @return void */ public function render( $field, $form_id ) { $describedby = $this->describedby( $field, $form_id ); $base = $this->input_id( $field, $form_id ); // After a failed send the visitor's name comes back instead of blank boxes. $sticky = $this->sticky_value( $field, $form_id ); ?>
wrapper_data( $field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped in wrapper_data().?>>
>
parts() as $key => $part ) : ?>
value="" />
render_description( $field, $form_id ); ?>
parts() as $key => $part ) { unset( $part ); $clean[ $key ] = isset( $value[ $key ] ) && is_scalar( $value[ $key ] ) ? sanitize_text_field( (string) $value[ $key ] ) : ''; } return $clean; } /** * Validation. * * @param mixed $value The value. * @param array $field The field settings. * * @return string */ public function validate( $value, $field ) { if ( empty( $field['required'] ) ) { return ''; } $first = is_array( $value ) && isset( $value['first'] ) ? trim( $value['first'] ) : ''; $last = is_array( $value ) && isset( $value['last'] ) ? trim( $value['last'] ) : ''; if ( '' === $first || '' === $last ) { return $this->required_message( $field ); } return ''; } /** * How it is shown in the entry. * * @param mixed $value The value. * @param array $field The field settings. * * @return string */ public function format_value( $value, $field ) { unset( $field ); if ( ! is_array( $value ) ) { return ''; } return trim( implode( ' ', array_filter( array_map( 'strval', $value ) ) ) ); } }