Categories > TinyButStrong general >

For Loop PHP to TBS

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Luke
Date: 2011-06-13
Time: 18:34

For Loop PHP to TBS

Hey I need help integrating some PHP loops into TBS syntax.  Here is my problem:

This code in a php file

  <select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">
            <?
            for ($i = 1; $i <= 12; $i++) {
                $link = $i+1;
                IF($_GET['month'] == $link){
                    $selected = "selected";
                } ELSE {
                    $selected = "";
                }
                echo "<option value=\"index2.php?month=$link&amp;year=$_GET[year]\" $selected>" . date ("F", mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";
            }
            ?>
          </select>

Needs to be placed into a topevel php file and then sent to the template file.  So I've created this:

function selcalmonth($i){
                    for ($i = 1; $i <= 12; $i++) {
                $link = $i+1;
                IF($_GET['month'] == $link){
                    $selected = "selected";
                } ELSE {
                    $selected = "";
                }
                echo "<option value=\"calendar.php?month=$link&amp;year=$_GET[year]\" $selected>" . date ("F", mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";
            }
               
                    }
                $selectMonth = selcalmotnh($i);
               

But I don't think it is right.

Can anyone help.  Thanks in advance!
By: Skrol29
Date: 2011-06-13
Time: 21:52

Re: For Loop PHP to TBS

Hi Luke,

It is not in the logic if a emplate engine to build the HTML snippet ate the PHP side.

Here is how you can do it with TBS:
Parameter "att" will move the TBS field at the place of the attribute. Then parameter "atttrue" will make ti to behave like a logical attribute (such as "selected")
HTML:
<option value="index2.php?month=[month.val]&amp;year=[onload._GET.year]">
  [month.val;att=option#selected;atttrue=onload._GET.month]
  [month.val;onformat=f_month]
</option>

PHP:
$TBS->MergeBlock('month', 'num', array('min'=>1,'max'=>12));
...
function f_month($FieldName, &$CurrVal) {
  $CurrVal = date("F", mktime(0, 0, 0, $CurrVal, 1, $_GET['year']);
}
By: Luke
Date: 2011-06-13
Time: 22:13

Re: For Loop PHP to TBS

Alright so I put this in the HTML:

<select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">
            <option value="calendar.php?month=[month.val]&amp;year=[onload._GET.year]">
                [month.val;att=option#selected;atttrue=onload._GET.month]
                [month.val;onformat=f_month]
            </option>
        </select>  
   

and this in the PHP:

$TBS->MergeBlock('month', 'num', array('min'=>1,'max'=>12));
...
function f_month($FieldName, &$CurrVal) {
                      $CurrVal = date("F", mktime(0, 0, 0, $CurrVal, 1, $_GET['year']));
            }

Yet it only produced one option:

<option value="calendar.php?month=1&amp;year=2011">1 January</option>


Did I do something wrong?

I need to have it produce the 12 months as options with the current month as selected.
By: Skrol29
Date: 2011-06-14
Time: 11:46

Re: For Loop PHP to TBS

Sorry, I've forgotten to add parameter "block". You can add it on any "month" field.
For example, replace
[month.val;onformat=f_month]
with
[month.val;block=option;onformat=f_month]