By: TomS
Date: 2010-01-02
Time: 20:12
|
Checkbox display
Ok, I'm new to using Tinybutstrong. I've gone through the example code and the forum looking for the answer but haven't been able to come up with the right combination of things to make this work for me.
I'm trying to click a checbox in a form, and have that box checked when redisplayed. It works in the test_funny code from the forum, but I can't seem to get the key right. Any help would be appreciated.
I've tried to pre define the array with keys and values but it hasn't helped.
$target_type = array("0"=>"","1"=>"","2"=>"","3"=>"");
----------
HTML
<table align="center" border="0" width="100%">
<tr><td align="left"><input type="checkbox" name="target_type[0]" value="0" [blktype.0;if [val]='0';then 'checked'] /> Profile Type</td>
<td align="left"><input type="checkbox" name="target_type[1]" value="1" [blktype.1;if [val]='1';then 'checked']/> Personal Profiles</td><td> </td>
PHP
$target_type[] = trim(strip_tags($_POST["target_type"]));
$TBS->MergeBlock('blktype', 'array', $target_type);
phpinfo()
_POST["target_type"] Array
(
[0] => 0
[1] => 1
)
Tinybutstrong error messages
TinyButStrong Error in field [blktype.0...] : item '0' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.
TinyButStrong Error in field [blktype.1...] : item '1' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.
The form when re-displayed dose not show the boxes checked.
|
By: Skrol29
Date: 2010-01-03
Time: 22:23
|
Re: Checkbox display
Hi TomS,
In your PHP snippet, TBS expects to have data which is an array of arrays. Each item of $target_type is supposed to be an array itself having the column named "0", "1"... Which is not.
TBS can merge single arrays but you have to use keywords "val" and "key" as virtual columns in the HTML side.
To have youe snippet working you can do like this:
HTML:
<td align="left"><input type="checkbox" name="target_type[0]" value="0" [onshow.target_type.0;if [val]='0';then 'checked'] />
Profile Type</td>
<td align="left"><input type="checkbox" name="target_type[1]" value="1" [onshow.target_type.1;if [val]='1';then 'checked']/>
|
PHP:
delete the line with MergeBlock.
|
By: TomS
Date: 2010-01-05
Time: 14:16
|
Re: Checkbox display
Thank you for the reply. I have tried what you suggested but with the same results. I'm trying to convert an existing php form to use Tinybutstrong, so I'm changing and testing one field at a time.
I've tried adding single quotes around the key value as shown in the Tinybutstrong manual, but that has not fixed the problem.
HTML
<form action="/advertiser_input_mmw.php" method="post">
<fieldset><legend>Advertiser Info</legend>
<table>
<tr><td>Advertiser Name:</td><td colspan="3"><input type="text" name="advertiser_name" size="50"/></td><tr>
<tr><td>Contact Name:</td><td colspan="3"><input type="text" name="contact_name" size="50"/></td></tr>
<tr><td>Advertiser Email:</td><td colspan="3"><input type="text" name="advertiser_email" size="50"/></td></tr>
</table>
</fieldset>
<fieldset><legend>Campaing Info</legend>
<table>
<tr><td>Start Date (MM/DD/YYYY):</td><td><input type="text" name="campaign_start" value="[onshow.campaign_start]"/></td></tr>
<tr><td>End Date (MM/DD/YYYY):</td><td><input type="text" name="campaign_end" value="[onshow.campaign_end]"/></td></tr>
<tr><td><input type="radio" name="option" value="impressions" />Impressions:</td><td><input type="text" name="target_impressions" size="5"/> X $.001</td></tr>
<tr><td><input type="radio" name="option" value="clicks" />Clicks:</td><td><input type="text" name="target_clicks" size="5"/> X $.005</td></tr>
<tr><td><input type="radio" name="option" value="sponsorship" checked/>Sponsorship:</td><td> @ $10.00 30 days</td></tr>
</table>
</fieldset>
<fieldset><legend>Campaign Targeting</legend>
<table>
<tr><td>
<table align="center" border="0" width="100%">
<tr><td align="left"><input type="checkbox" name="target_type['0']" value="0" [onshow.target_type.0;if [val]="0";then 'checked'] /> Profile Type</td>
<td align="left"><input type="checkbox" name="target_type['1']" value="1" [onshow.target_type.1;if [val]='1';then 'checked'] /> Personal Profiles</td><td> </td>
<td align="left"><input type="checkbox" name="target_gender" /> Gender</td>
<td align="left"><input type="radio" name="gender" value="male" /> Male</td><td> </td>
<td align="left"><input type="checkbox" name="target_age" /> Age</td>
<td align="left"> From: <select name="age_from" size="1" id="age_from">
<option value="[fromblk.val]">[fromblk.key;block=option]</option>
<option>[onshow.age_from;ope=html;select]</option>
</select></td></tr>
<tr><td align="left"> X .005 </td><td align="left"><input type="checkbox" name="target_type['2']" value="2" [onshow.target_type.2;if [val]='2'; 'checked']/> Professional Profiles</td><td> </fon></td>
<td align="left"> X .005 </td><td align="left"><input type="radio" name="gender" value="female" /> Female</td><td> </td>
<td align="left"> X .005 </td><td align="left"> To: <select name="age_to" size="1" id="age_to">
<option value="[toblk.val]">[toblk.key;block=option]</option>
<option>[onshow.age_to;ope=html;select]</option>
</select></td></tr>
<tr><td> </td><td align="left"><input type="checkbox" name="target_type['3']" value="3" [onshow.target_type.3;if [val]='3'; 'checked']/> Educational Profiles</td><td> </td>
<td colspan="2"> </td><td> </td><td colspan="2"> </td></tr>
</table>
</fieldset>
</td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Calculate" name="step"></td></tr>
</table>
<input type="hidden" name="req" value="calculate">
</form>
PHP
<?php
include_once('classes/tbs_class.php');
include_once('classes/plugins/tbs_plugin_html.php'); // Plug-in for selecting HTML items.
$from_age = array("Under"=>"Under","15"=>"15","18"=>"18","21"=>"21","25"=>"25","30"=>"30",
"35"=>"35","40"=>"40","45"=>"45","50"=>"50","55"=>"55","60"=>"60","65"=>"65");
$to_age = array("Over "=>"Over","15"=>"15","18"=>"18","21"=>"21","25"=>"25","30"=>"30",
"35"=>"35","40"=>"40","45"=>"45","50"=>"50","55"=>"55","60"=>"60","65"=>"65");
switch($_REQUEST['step']){
case "Calculate":
// phpinfo();
$TBS =& new clsTinyButStrong ;
$TBS->LoadTemplate('Advertiser_signup_form_mmw.html') ;
$TBS->MergeBlock('fromblk',$from_age);
$TBS->MergeBlock('toblk',$to_age);
$advertiser_name = trim(strip_tags($_POST["advertiser_name"]));
$contact_name = trim(strip_tags($_POST["contact_name"]));
$advertiser_email = trim(strip_tags($_POST["advertiser_email"]));
$campaign_start = trim(strip_tags($_POST["campaign_start"]));
$campaign_end = trim(strip_tags($_POST["campaign_end"]));
$option = trim(strip_tags($_POST["option"]));
$target_impressions = trim(strip_tags($_POST["target_impressions"]));
$target_clicks = trim(strip_tags($_POST["target_clicks"]));
$target_type[] = trim(strip_tags($_POST["target_type"]));
$personal = trim(strip_tags($_POST["personal"]));
$professional = trim(strip_tags($_POST["professional"]));
$educational = trim(strip_tags($_POST["educational"]));
$target_gender = trim(strip_tags($_POST["target_gender"]));
$gender = trim(strip_tags($_POST["gender"]));
$target_age = trim(strip_tags($_POST["target_age"]));
$age_from = trim(strip_tags($_POST["age_from"]));
$age_to = trim(strip_tags($_POST["age_to"]));
$TBS->Show() ;
break;
Error message:
After checking several boxes I receive the following errors and the checkboxes are not checked on re-display of the form.
TinyButStrong Error in field [onshow.target_type.1...] : item '1' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.
TinyButStrong Error in field [onshow.target_type.2...] : item '2' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.
TinyButStrong Error in field [onshow.target_type.3...] : item '3' is not an existing key in the array. This message can be cancelled using parameter 'noerr'
|