Skip to content

Commit

Permalink
Support fields formed using bw_tablerow or bw_gridrow #207
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 10, 2022
1 parent 113c12a commit 34d3a03
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 25 deletions.
106 changes: 95 additions & 11 deletions libs/bobbforms.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php // (C) Copyright Bobbing Wide 2009-2022
if ( !defined( "BOBBFORMS_INCLUDED" ) ) {
define( "BOBBFORMS_INCLUDED", "3.3.0" );
define( "BOBBFORMS_INCLUDED", "3.4.0" );

/**
* Library: bobbforms
Expand Down Expand Up @@ -331,8 +331,12 @@ function bw_textfield( $name, $len, $text, $value, $class=null, $extras=null, $a
if ( $value === null ) {
$value = bw_array_get( $_REQUEST, $name, null );
}
$itext = itext( $name, $len, $value, $class, $extras, $args );
bw_tablerow( array( $lab, $itext ) );
$itext = itext( $name, $len, $value, $class, $extras, $args );
if ( bw_is_table() ) {
bw_tablerow(array($lab, $itext));
} else {
bw_gridrow(array($lab, $itext));
}
return;
}

Expand All @@ -351,8 +355,12 @@ function bw_emailfield( $name, $len, $text, $value, $class=null, $extras=null )
if ( $value === null ) {
$value = bw_array_get( $_REQUEST, $name, null );
}
$itext = iemail( $name, $len, $value, $class, $extras );
bw_tablerow( array( $lab, $itext ) );
$itext = iemail( $name, $len, $value, $class, $extras );
if ( bw_is_table() ) {
bw_tablerow(array($lab, $itext));
} else {
bw_gridrow(array($lab, $itext));
}
return;
}

Expand All @@ -378,8 +386,12 @@ function bw_textarea( $name, $len, $text, $value, $rows=10, $args=null ) {
if ( null !== $spellcheck ) {
$spellcheck = kv( "spellcheck", $spellcheck );
}
$itext = iarea( $name, $len, $value, $rows, $spellcheck );
bw_tablerow( array( $lab, $itext) );
$itext = iarea( $name, $len, $value, $rows, $spellcheck );
if ( bw_is_table() ) {
bw_tablerow(array($lab, $itext));
} else {
bw_gridrow(array($lab, $itext));
}
return;
}

Expand All @@ -403,7 +415,11 @@ function bw_radio( $name, $text, $values, $labels, $class=null, $extras=null ) {
$iradios .= iradio( $name, $id, $value, $class, $extra );
}
$lab = label( $name, $text );
bw_tablerow( array( $lab, $iradios ) );
if ( bw_is_table() ) {
bw_tablerow(array($lab, $iradios));
} else {
bw_gridrow(array($lab, $radios));
}
}

/**
Expand Down Expand Up @@ -532,8 +548,12 @@ function iselect( $name, $value, $args ) {
*/
function bw_select( $name, $text, $value, $args ) {
$lab = label( $name, $text );
$iselect = iselect( $name, $value, $args );
bw_tablerow( array( $lab, $iselect ) );
$iselect = iselect( $name, $value, $args );
if ( bw_is_table() ) {
bw_tablerow(array($lab, $iselect));
} else {
bw_gridrow(array($lab, $iselect));
}
return;
}

Expand Down Expand Up @@ -578,7 +598,11 @@ function icheckbox( $name, $value=NULL, $disabled=false ) {
function bw_checkbox( $name, $text, $value=1, $args=NULL ) {
$lab = BW_::label( $name, $text );
$icheckbox = icheckbox( $name, $value );
bw_tablerow( array( $lab, $icheckbox ));
if ( bw_is_table() ) {
bw_tablerow(array($lab, $icheckbox));
} else {
bw_gridrow(array($lab, $icheckbox));
}
return;
}

Expand Down Expand Up @@ -775,4 +799,64 @@ function bw_verify_nonce( $action, $name ) {
}
}


/**
* Starts a table or grid.
*
* @since v3.4.0
* @param null $table
*/
function bw_table_or_grid_start( $table=null ) {
bw_is_table( $table );
if ( $table ) {
stag( 'table');
} else {
sdiv( 'bw_grid');
}
}

/**
* Ends a table or grid.
* @since v3.4.0
*/
function bw_table_or_grid_end() {
if ( bw_is_table() ) {
etag( 'table');
} else {
ediv();
}
}

/**
* Checks for/sets table or grid.
*
* @since v3.4.0
* @param $table
* @return mixed
*/
function bw_is_table( $table=null ) {
static $bw_table_or_grid;
if ( null !== $table ) {
$bw_table_or_grid = $table;

}
bw_trace2( $bw_table_or_grid, "table or grid");
return $bw_table_or_grid;
}

/**
* Displays a row as a grid.
* @since v3.4.0
* @param $array
*/
function bw_gridrow( $array ) {
if ( count( $array ) ) {
foreach ($array as $item) {
sdiv();
e($item);
ediv();
}
}
}

} /* end !defined */
57 changes: 46 additions & 11 deletions libs/class-BW-.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php // (C) Copyright BobbingWide 2017-2022
if ( !defined( "CLASS_BW__INCLUDED" ) ) {
define( "CLASS_BW__INCLUDED", "3.2.2" );
define( "CLASS_BW__INCLUDED", "3.3.0" );

/**
* More HTML output library functions
Expand Down Expand Up @@ -170,8 +170,12 @@ static function bw_textfield( $name, $len, $text, $value, $class=null, $extras=n
if ( $value === null ) {
$value = bw_array_get( $_REQUEST, $name, null );
}
$itext = itext( $name, $len, $value, $class, $extras, $args );
bw_tablerow( array( $lab, $itext ) );
$itext = itext( $name, $len, $value, $class, $extras, $args );
if ( self::is_table() ) {
bw_tablerow(array($lab, $itext));
} else {
bw_gridrow(array($lab, $itext));
}
return;
}

Expand Down Expand Up @@ -207,8 +211,12 @@ static function bw_emailfield( $name, $len, $text, $value, $class=null, $extras=
if ( $value === null ) {
$value = bw_array_get( $_REQUEST, $name, null );
}
$itext = iemail( $name, $len, $value, $class, $extras );
bw_tablerow( array( $lab, $itext ) );
$itext = iemail( $name, $len, $value, $class, $extras );
if ( self::is_table() ) {
bw_tablerow(array($lab, $itext));
} else {
bw_gridrow(array($lab, $itext));
}
return;
}

Expand Down Expand Up @@ -251,8 +259,12 @@ static function bw_textarea( $name, $len, $text, $value, $rows=10, $args=null )
if ( null !== $spellcheck ) {
$spellcheck = kv( "spellcheck", $spellcheck );
}
$itext = iarea( $name, $len, $value, $rows, $spellcheck );
bw_tablerow( array( $lab, $itext) );
$itext = iarea( $name, $len, $value, $rows, $spellcheck );
if ( self::is_table() ) {
bw_tablerow(array($lab, $itext));
} else {
bw_gridrow(array($lab, $itext));
}
return;
}

Expand Down Expand Up @@ -317,7 +329,11 @@ static function bw_radio( $name, $text, $values, $labels, $class=null, $extras=n
$iradios .= iradio( $name, $id, $value, $class, $extra );
}
$lab = BW_::label( $name, $text );
bw_tablerow( array( $lab, $iradios ) );
if ( self::is_table() ) {
bw_tablerow(array($lab, $iradios));
} else {
bw_gridrow(array($lab, $iradios));
}
}

/**
Expand All @@ -330,8 +346,12 @@ static function bw_radio( $name, $text, $values, $labels, $class=null, $extras=n
*/
static function bw_select( $name, $text, $value, $args ) {
$lab = BW_::label( $name, $text );
$iselect = iselect( $name, $value, $args );
bw_tablerow( array( $lab, $iselect ) );
$iselect = iselect( $name, $value, $args );
if ( self::is_table() ) {
bw_tablerow(array($lab, $iselect));
} else {
bw_gridrow(array($lab, $iselect));
}
return;
}

Expand Down Expand Up @@ -385,7 +405,22 @@ static function br( $text=null ) {
if ( $text ) {
e( $text );
}
}
}

/*
* Determines display format.
*
* @since 3.3.0
* @return bool - true for bw_tablerow, false for bw_gridrow
*/
static function is_table() {
if ( function_exists( 'bw_is_table')) {
$is_table = bw_is_table();
} else {
$is_table = true;
}
return $is_table;
}



Expand Down
17 changes: 14 additions & 3 deletions shortcodes/oik-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ function bw_contact_form_submit_button( $atts ) {
*/
function _bw_show_contact_form_oik( $atts, $user=null, $content=null ) {
$email_to = bw_get_option_arr( "email", null, $atts );
oik_require( "bobbforms.inc" );
oik_require_lib( "bobbforms", "3.4.0" );
$class = bw_array_get( $atts, "class", "bw_contact_form" );
sdiv( $class );
bw_form();
stag( "table" );
//stag( "table" );
if ( function_exists( 'bw_is_table')) {
bw_table_or_grid_start( false ); // Start a grid
} else {
stag( 'table' );
}
if ( $content ) {
_bw_show_contact_form_fields($atts, $content);
} else {
Expand All @@ -93,7 +98,13 @@ function _bw_show_contact_form_oik( $atts, $user=null, $content=null ) {
}
// @TODO Optional "required" checkbox
//bw_checkbox( "oiku_checkbox,
etag( "table" );
//etag( "table" );
if ( function_exists( 'bw_is_table')) {
bw_table_or_grid_end();
} else {
etag( 'table');
}

e( wp_nonce_field( "_oik_contact_form", "_oik_contact_nonce", false, false ) );
e( ihidden( "oiku_email_to", $email_to ) );
oik_require_lib( "oik-honeypot" );
Expand Down

0 comments on commit 34d3a03

Please sign in to comment.