Categories > TinyButStrong general >

ope=html;select='consult_type[]' not selecting of val contains &

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: TomH
Date: 2013-08-20
Time: 06:20

ope=html;select='consult_type[]' not selecting of val contains &

Hello
Stumbled across this anomoly - I hope  someone has seen this behavior and can help.

When attempting to check checkboxes -- none are checked  that have a valus that contains an "&" (that comes from the dataabase 

The mysql data come from a SET('Acoustical','ADA Compliance','Architectural Illustrators / Rendering','Art Consultants','Artists','Audio/Visual/Acoustics','Code Consultants','Commissioning','Web Design & Development','Furniture Repair & Refinishing','Drapery Fabrication','Recyclers') field

To get the values for creating and  checking the checkboxes the PHP. is...

function set_field_array($table, $field){
  global $Db;
  $sql = "DESCRIBE $table $field";
  $result = $Db->GetRow($sql);
  $set = $result['Type'];
  $trimmedset = ltrim(rtrim($set, "')"), "set('");
  $set_list = split("','", $trimmedset);
  foreach($set_list AS $key=>$val){
    $set_array[] = array('num'=>$key, 'type'=>$val);
  }
return $set_array;
}

$contact_type_setarray = set_field_array($table_name, $set_field);

$querytext= "select * from $table_name WHERE $index_field = $key";

if($result = $Db->GetRows($querytext)){

//  ---------------  create array of values to CHECK the checkboxes   ----------------
$contact_type_values = explode(",", $result[0][$set_field]);

$TBS->LoadTemplate($casetemplate) ;

// merge to create the mpty checkboxes
$TBS->MergeBlock('by', $contact_type_setarray);

// merge to fill remainder of form data
$TBS->MergeBlock('blk1',$result);

    }

$TBS->Show() ;

The template
<table>                                           
<!-- [onshow.contact_type_values;htmlconv=no;ope=html;select='consult_type[]'] -->
<tr>
<td>
<input class="check-box" type="checkbox" name="consult_type[]" value="[by.type; noerr]"  />
</td>
<td>
[by.type; block=tr; noerr]
</td>
</tr>   
</table>       

The array of data from the database, for use by the ope=html; select, looks like this...
$contact_type_values=
Array
(
[0] => Food Service
[1] => Staffing & Placement Services
[2] => Web Design & Development
[3] => Furniture Repair & Refinishing
)

In the rendered page ONLY the "Food Service" checkbox is checked
The html (page source) that is generated from the same database SET() field renders the "&" correctly

Any one have any ideas about the source of the problem and any possible fix?

Thanks for TBS every day,
TomH
By: Sarah Kemp
Date: 2013-08-20
Time: 17:10

Re: ope=html;select='consult_type[]' not selecting of val contains &

If the problem is the ampersand, have you tried html encoding it? It is not standard to use a bare '&' in HTML, you should be using '&amp;'. Could try: http://php.net/manual/en/function.htmlspecialchars.php

Where is your logic for checking the checkbox? I don't see any reference in the code you provided. Are you seeing all of your checkboxes display properly with their description, and the only thing wrong in the lack of check mark?
By: TomH
Date: 2013-08-25
Time: 01:16

Re: ope=html;select='consult_type[]' not selecting of val contains &

Sarah

About checking the boxes = in the above there's
the php
$contact_type_values = explode(",", $result[0][$set_field]);
and above the template uses
[onshow.contact_type_values;htmlconv=no;ope=html;select='consult_type[]']


In the displayed page, for the checkboxes... the "value" is displayed correctly for all of the vals that include the ampersand
but when there's a "contact_type_values" that includes an ampersand (correctly) ... the box is not checked
By: Skrol29
Date: 2013-08-25
Time: 23:11

Re: ope=html;select='consult_type[]' not selecting of val contains &

Hi,

Despite the value is correctly displayed by the brother, the HTML standard expects that ampersands (&) are specail characters that should be coded with '&amp;' in attributes.

Nevertheless, I think your problem is not due to the standard.
TBS does protects this special char by default. That is: any merged value is converted into correct HTML by replacing special chars such as '&'.
If you specify "htmlconv=no" then there is no replacement.
Thus, in the merged values '&' is replaced with '&amp;', while in the fields that select items ([onshow.contact_type_values;htmlconv=no;ope=html;select='consult_type[]'])  '&' is not replaced.
So it doesn't match.
By: Anonymous
Date: 2013-08-29
Time: 00:34

Re: ope=html;select='consult_type[]' not selecting of val contains &

Skrol29

That makes sense good -- thanks very much for making it understood

I will try it without the htmlconv=no in the ope=html field

Thanks for TBS every day,
TomH