Categories > TinyButStrong general >

Enter data in a form example

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: andrew
Date: 2010-09-13
Time: 16:31

Enter data in a form example

I am new to TBS and Joomla with very basic php and mysql knowlege so this will likely be a very simple oversight.

I am working with Joomla and the examples to learn the system. I managed to get the 'Data MySQL' example working fine with an external database.

However, having copied the 'Enter data in a form' example to the Joomla site, I get the following error when clicking on the relevant Joomla link:

TinyButStrong Error in field [onshow.x_type...] : the PHP global variable named 'x_type' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [onshow.x_name...] : the PHP global variable named 'x_name' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [onshow.x_subname...] : the PHP global variable named 'x_subname' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [onshow.msg_color...] : the PHP global variable named 'msg_color' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [onshow.msg_text...] : the PHP global variable named 'msg_text' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

The source code for the displayed page is below:

<br /><b>TinyButStrong Error</b> in field &#91;onshow.x_type...] : the PHP global variable named 'x_type' does not exist or is not set yet. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> in field &#91;onshow.x_name...] : the PHP global variable named 'x_name' does not exist or is not set yet. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> in field &#91;onshow.x_subname...] : the PHP global variable named 'x_subname' does not exist or is not set yet. <em>This message can be cancelled using parameter 'noerr'.</em><br />

<br /><b>TinyButStrong Error</b> in field &#91;onshow.msg_color...] : the PHP global variable named 'msg_color' does not exist or is not set yet. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> in field &#91;onshow.msg_text...] : the PHP global variable named 'msg_text' does not exist or is not set yet. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<form action="index.php" method="post" name="frm_info" id="frm_info">
  <table width="300" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>

      <td width="296"><table width="100%" border="1" cellpadding="0" cellspacing="0">
          <tr>
            <td height="20" bgcolor="#BBCCED">Enter information:</td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
                <tr align="left" valign="bottom" class="back-special2">
                  <td width="76">Gender : </td>

                  <td width="212"><select name="x_type" class="normal" id="select2">
                      <option value="-">&lt;other&gt;</option><option value="Mr">Mister</option><option value="Mme">Madame</option><option value="Ms">Missis</option>
                      <option>[onshow.x_type;ope=html;select]</option>
                    </select>
                  </td>
                </tr>

                <tr align="left" valign="bottom" class="back-special2">
                  <td>Last name: </td>
                  <td><input name="x_name" type="text" class="normal" id="x_name2" value="[onshow.x_name]">
                  </td>
                </tr>
                <tr align="left" valign="bottom" class="back-special2">
                  <td>First name:</td>
                  <td><input name="x_subname" type="text" class="normal" id="x_subname2" value="[onshow.x_subname]">

                  </td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td height="30" bgcolor="#BBCCED"><div align="center">
                <input name="btn_save" type="submit" class="normal" id="btn_save2" value="  Validate  ">
              </div></td>
          </tr>

        </table></td>
    </tr>
  </table>
  <div align="center"><br>
    <strong><font color="[onshow.msg_color]">[onshow.msg_text]</font></strong> </div>
</form>

Why is this page being displayed out of the joomla site and how do I fix these errors as there is nothing in the example files defining these global variables that I noticed?
By: Skrol29
Date: 2010-09-13
Time: 23:51

Re: Enter data in a form example

Hi,

> as there is nothing in the example files defining these global variables that I noticed?

Yes there is. See the PHP script corresponding to this example, the global variables are defined there.
By: andrew
Date: 2010-09-14
Time: 07:59

Re: Enter data in a form example

Thank you for the quick reply, I am very greatfull for your help. I am puzzled as I have not changed anything in the example script except the file paths to the relevant includes and template files.

Any ideas what I have done wrong?

Script as below:


  <?php

include_once('/path_to_joomla_installation/plugins/content/tinybutstrong_class_php5.php');
include_once('/path_to_joomla_installation/plugins/content/tbs_plugin_html.php'); // Plug-in for selecting HTML items.


$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('/path_to_joomla_installation/plugins/tbs_htm_templates/test_form.html');

$typelist = array('<other>'=>'-','Mister'=>'Mr','Madame'=>'Mme','Missis'=>'Ms') ;
$TBS->MergeBlock('typeblk',$typelist) ;

if (!isset($_POST)) $_POST=&$HTTP_POST_VARS;
if (!isset($_POST['x_type'])) {
  $x_type = '-' ;
  $x_name = '' ;
  $x_subname = '' ;
  $msg_text = 'Enter your information and click on [Validate].' ;
  $msg_color = '#0099CC' ; //blue
} else {
  $msg_text = '';
  $msg_body = array();
    $x_type = $_POST['x_type'];
    $x_name = $_POST['x_name'];
    $x_subname = $_POST['x_subname'] ;
  if (trim($x_type)=='-')   $msg_body[] = ' your gender' ;
  if (trim($x_name)=='')    $msg_body[] = ' your last name' ;
  if (trim($x_subname)=='') $msg_body[] = ' your first name' ;
  if (count($msg_body)==0) {
    $msg_text = 'Thank you.' ;
    $msg_color = '#336600' ; //green
    } else {
    $msg_text = 'Please enter' . join($msg_body, ' and');
    $msg_color = '#990000' ; //red
    }
}

$TBS->Show();

?>

By: Skrol29
Date: 2010-09-15
Time: 10:28

Re: Enter data in a form example

hi Andrew,

When you are using the TBS plug-in for Joomla, then external script are run in the context of a function, thus variables declared in script called by the plugin are not global but local.

This is mentioned in the manual: "Please note that your PHP script is run in the same context as a function and that the local variable $TBS contains the ready to use TBS instance."
You can turn the local variables into global variables using the PHP instruction "global"
There is also no need to create a new $TBS instance, it is already provided by the plug-in and the current article is already loaded.

By: andrew
Date: 2010-09-15
Time: 16:24

Re: Enter data in a form example

Thanks for the reply. Removing the '$TBS->Show();' from the end means the template form is now being displayed in the joomla article.

However, am I correct in thinking the 'tbs_plugin_html.php' include is responsible for hiding the '[onshow.x_name]' from the html form displayed in the browser.

This is not currently working as it does in the example and I can not work out why.

The view source for the joomla article is below.

<tr>
<td valign="top">
<form action="[onshow..script_name]" method="post" name="frm_info" id="frm_info">
  <table width="300" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="296"><table width="100%" border="1" cellpadding="0" cellspacing="0">

          <tr>
            <td height="20" bgcolor="#BBCCED">Enter information:</td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
                <tr align="left" valign="bottom" class="back-special2">
                  <td width="76">Gender : </td>
                  <td width="212"><select name="x_type" class="normal" id="select2">

                      <option value="-">&lt;other&gt;</option><option value="Mr">Mister</option><option value="Mme">Madame</option><option value="Ms">Missis</option>
                      <option>[onshow.x_type;ope=html;select]</option>
                    </select>
                  </td>
                </tr>
                <tr align="left" valign="bottom" class="back-special2">

                  <td>Last name: </td>
                  <td><input name="x_name" type="text" class="normal" id="x_name2" value="[onshow.x_name]">
                  </td>
                </tr>
                <tr align="left" valign="bottom" class="back-special2">
                  <td>First name:</td>
                  <td><input name="x_subname" type="text" class="normal" id="x_subname2" value="[onshow.x_subname]">
                  </td>

                </tr>
              </table></td>
          </tr>
          <tr>
            <td height="30" bgcolor="#BBCCED"><div align="center">
                <input name="btn_save" type="submit" class="normal" id="btn_save2" value="  Validate  ">
              </div></td>
          </tr>
        </table></td>

    </tr>
  </table>
  <div align="center"><br>
    <strong><font color="[onshow.msg_color]">[onshow.msg_text]</font></strong> </div>
</form></td>
</tr>