array( __( 'Street address', '2ranq-forms' ), 'street-address', true ), 'line2' => array( __( 'Apartment, suite, floor', '2ranq-forms' ), 'address-line2', true ), 'city' => array( __( 'City', '2ranq-forms' ), 'address-level2', false ), 'region' => array( __( 'Region', '2ranq-forms' ), 'address-level1', false ), 'postal' => array( __( 'Postal code', '2ranq-forms' ), 'postal-code', false ), 'country' => array( __( 'Country', '2ranq-forms' ), 'country-name', false ), ); } /** * The type. * * @return string */ public function get_type() { return 'address'; } /** * The name in the builder. * * @return string */ public function get_label() { return __( 'Address', '2ranq-forms' ); } /** * The icon. * * @return string */ public function get_icon() { return 'dashicons-location'; } /** * The group. * * @return string */ public function get_group() { return 'fancy'; } /** * The name the value arrives under. * * @param array $field The field settings. * * @return string */ protected function input_name( $field ) { return 'ranq_fields[' . $this->field_key( $field ) . ']'; } /** * Prints the field. * * @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 address 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. A required address asks for the street and the city, the rest * is optional. * * @param mixed $value The value. * @param array $field The field settings. * * @return string */ public function validate( $value, $field ) { if ( empty( $field['required'] ) ) { return ''; } $street = is_array( $value ) && isset( $value['street'] ) ? trim( $value['street'] ) : ''; $city = is_array( $value ) && isset( $value['city'] ) ? trim( $value['city'] ) : ''; if ( '' === $street || '' === $city ) { 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 implode( ', ', array_filter( array_map( 'strval', $value ) ) ); } }