Skip to content

Commit

Permalink
Support required fields by label containing * or required attribute #207
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 5, 2022
1 parent 3dc01db commit d5c9ef4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion shortcodes/oik-contact-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ function bw_contact_field( $atts, $content, $tag ) {
$args = [ '#length' => 30 ];
$value = bw_array_get( $atts, 'value', null);
$args['value'] = $value;
$required = bw_array_get( $atts, 'required', '0');

/**
* Sets the required flag in #extras if the Label contains a '*' or the
* required attribute is set.
*/
$required = ( false !== strpos( $label, '*' ) ) ? 'y' : 'n';
$required = bw_array_get( $atts, 'required', $required);
$args['required'] = $required;
if ( bw_validate_torf( $required ) ) {
$args['#extras'] = 'required';
}

// The prefix could be set in the bw_contact_form shortcode or the first instance of the bw_contact_field shortcode.
//$prefix = bw_contact_form_prefix( 'oiku_');
Expand Down
2 changes: 1 addition & 1 deletion shortcodes/oik-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ function _bw_show_contact_form_fields() {
bw_trace2( $field, "Field", false, BW_TRACE_DEBUG );
if ( $field ) {
$value = ''; // $field['#value']
bw_form_field( $full_name, $field['#field_type'], $field['#title'], $value , $bw_fields[ $full_name ]);
bw_form_field( $full_name, $field['#field_type'], $field['#title'], $value , $bw_fields[ $full_name ]['#args']);
}
}
$bw_contact_fields = [];
Expand Down

0 comments on commit d5c9ef4

Please sign in to comment.