Categories > TinyButStrong general >

funny example : edit one or more rows at the same time

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: olivier
Date: 2005-01-25
Time: 11:19

funny example : edit one or more rows at the same time

Hello !

To test the differents input html tags (text, hidden, select, select multiple, radio and checkbox) with TBS, I've made an example to edit one or more rows at the same time.

the php page : test_funny.php
<?
// ============================================================================
// P H P
// ============================================================================

set_time_limit (30);
error_reporting(E_ALL);

// ============================================================================
// I N C L U D E
// ============================================================================

include_once('tbs_class.php');

// ============================================================================
// P O S T   P A R A M E T E R S
// ============================================================================

if (0) {
  echo '<pre>POST'."\n";
  print_r($_POST);
  echo '</pre>';
}

$init  = (isset($_POST['init'])  ? $_POST['init']  : 0);
$data  = (isset($_POST['data'])  ? $_POST['data']  : array());

if (!$init) { // default value
  $data[0]['field_text']     = 'text 1';
  $data[0]['field_hidden']   = 'hidden 1';
  $data[0]['field_select']   = '1';
  $data[0]['field_multiple'] = '1';
  $data[0]['field_radio']    = '1';
  $data[0]['field_checkbox'] = '1';

  $data[1]['field_text']     = 'text 2';
  $data[1]['field_hidden']   = 'hidden 2';
  $data[1]['field_select']   = '2';
  $data[1]['field_multiple'] = array('1','2');
  $data[1]['field_radio']    = '2';
  $data[1]['field_checkbox'] = '0';

  $data[2]['field_text']     = 'text 3';
  $data[2]['field_hidden']   = 'hidden 3';
  $data[2]['field_select']   = '3';
  $data[2]['field_multiple'] = '3';
  $data[2]['field_radio']    = '3';
  $data[2]['field_checkbox'] = '1';

} else {  // post value
  $new_data = array();
  while (list($key, $field) = each($data)) {
    $new_data[$key]['field_text']     = (isset($field['field_text'])        ? $field['field_text']        : '');
    $new_data[$key]['field_hidden']   = (isset($field['field_hidden'])      ? $field['field_hidden']      : '');
    $new_data[$key]['field_select']   = (isset($field['field_select'])      ? $field['field_select']      : '0');
    $new_data[$key]['field_multiple'] = (isset($field['field_multiple'])    ? $field['field_multiple']    : array());
    $new_data[$key]['field_radio']    = (isset($field['field_radio_'.$key]) ? $field['field_radio_'.$key] : '0');
    $new_data[$key]['field_checkbox'] = (isset($field['field_checkbox'])    ? $field['field_checkbox']    : '0');
  }
  $data =&$new_data;
}

// ============================================================================
// M A I N
// ============================================================================

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('test_funny.html');

// load the select
$select[0]['option_id']    = '1';
$select[0]['option_value'] = 'option 1';
$select[1]['option_id']    = '2';
$select[1]['option_value'] = 'option 2';
$select[2]['option_id']    = '3';
$select[2]['option_value'] = 'option 3';
$TBS->MergeBlock('blk_select',  'array', $select);

// load the select multiple
$multiple[0]['option_id']    = '1';
$multiple[0]['option_value'] = 'option 1';
$multiple[1]['option_id']    = '2';
$multiple[1]['option_value'] = 'option 2';
$multiple[2]['option_id']    = '3';
$multiple[2]['option_value'] = 'option 3';
$TBS->MergeBlock('blk_multiple','array', $multiple);

// display datas
$TBS->MergeBlock('blk_data',    'array', $data);

// ============================================================================
// E N D
// ============================================================================

$TBS->Show();
?>



the htmlpage : test_funny.html
<html>
<head>
<title>funny test</title>
</head>
<body>
<form method="post" action="[var..script_name]">
<input type="hidden" name="init" value="1">
<table border=1>
<tr>
  <th>text</th>
  <th>select</th>
  <th>multiple</th>
  <th colspan=3>radio</th>
  <th>checkbox</th>
</tr>
<tr>
  <td>
    <input type="text"     name="data[[blk_data.$]][field_text]"              value="[blk_data.field_text;block=tr]">
    <input type="hidden"   name="data[[blk_data.$]][field_hidden]"            value="[blk_data.field_hidden]">
  </td>
  <td>
    <select name="data[[blk_data.$]][field_select]">
      <option value="">*** select ***</option>
      <option value="[blk_select.option_id;block=option]">[blk_select.option_value]</option>
      <option>[blk_data.field_select;selected;selbounds=select]</option>
    </select>
  </td>
  <td>
    <select name="data[[blk_data.$]][field_multiple][]" multiple>
      <option value="[blk_multiple.option_id;block=option]">[blk_multiple.option_value]</option>
      <option>[blk_data.field_multiple;selected;selbounds=select]</option>
    </select>
  </td>
  <radio [blk_data.field_radio;selected=data[[blk_data.$]][field_radio_[blk_data.$]];selbounds=radio]>
  <td><input type="radio"    name="data[[blk_data.$]][field_radio_[blk_data.$]]"    value="1"></td>
  <td><input type="radio"    name="data[[blk_data.$]][field_radio_[blk_data.$]]"    value="2"></td>
  <td><input type="radio"    name="data[[blk_data.$]][field_radio_[blk_data.$]]"    value="3"></td>
  </radio>
  <td><input type="checkbox" name="data[[blk_data.$]][field_checkbox]"              value="1" [blk_data.field_checkbox;if [val]='1';then 'checked']></td>
</tr>
<tr>
  <td colspan=7><input type="submit"></td>
</tr>
</table>
</form>
</body>