Skip to content

Commit

Permalink
Support requiredIndicator attribute for contact field #207
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 11, 2022
1 parent 5d5ec92 commit 60ac7ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions shortcodes/oik-contact-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ function bw_contact_field( $atts, $content, $tag ) {
/**
* Sets the required flag in #extras if the Label contains a '*' or the
* required attribute is set.
* If required sets the requiredindicator to '*' by default.
*/
$required = ( false !== strpos( $label, '*' ) ) ? 'y' : 'n';
$required = bw_array_get( $atts, 'required', $required);
$args['required'] = $required;
if ( bw_validate_torf( $required ) ) {
$label = str_replace( '*', '', $label );
$args['#extras'] = 'required';
$requiredIndicator = bw_array_get( $atts, 'requiredindicator', '*');
if (null !== $requiredIndicator) {
$label .= '<span class="required">' . $requiredIndicator . '</span>';
}
}

// The prefix could be set in the bw_contact_form shortcode or the first instance of the bw_contact_field shortcode.
Expand Down
10 changes: 5 additions & 5 deletions shortcodes/oik-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ function _bw_show_contact_form_oik( $atts, $user=null, $content=null ) {
$class = bw_array_get( $atts, "class", "bw_contact_form" );
sdiv( $class );
bw_form();
//stag( "table" );
if ( function_exists( 'bw_is_table')) {
bw_table_or_grid_start( false ); // Start a grid
} else {
Expand All @@ -96,10 +95,7 @@ function _bw_show_contact_form_oik( $atts, $user=null, $content=null ) {
BW_::bw_textfield( bw_contact_field_full_name( "subject" ), 30, __("Subject", "oik"), null, "textBox");
BW_::bw_textarea( bw_contact_field_full_name( "message" ), 30, __("Message", "oik"), null, 10);
}
// @TODO Optional "required" checkbox
//bw_checkbox( "oiku_checkbox,
//etag( "table" );
if ( function_exists( 'bw_is_table')) {
if ( function_exists( 'bw_is_table')) {
bw_table_or_grid_end();
} else {
etag( 'table');
Expand Down Expand Up @@ -521,6 +517,10 @@ function bw_contact_field_to_shortcode( $attrs ) {
$required = bw_array_get( $attrs, 'required', false );
if ( $required ) {
$content .= ' required=y';
$requiredIndicator = bw_array_get( $attrs, 'requiredIndicator', null );
if ( null !== $requiredIndicator ) {
$content .= ' requiredindicator="' . $requiredIndicator . '"';
}
}
$content .= "]";
return $content;
Expand Down

0 comments on commit 60ac7ef

Please sign in to comment.