11
Dave_L
Re: Using forms in functions
  • 2005/4/3 8:54

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I have one module in which I used Smarty templates and forms on the admin side. Here's the relevant code:

require_once XOOPS_ROOT_PATH '/include/cp_header.php';
require_once 
XOOPS_ROOT_PATH '/class/template.php';
require_once 
XOOPS_ROOT_PATH '/class/xoopsformloader.php';
...
if (!isset(
$xoopsTpl)) {
   
$xoopsTpl = new XoopsTpl();
}
...
function 
dlinstallx_admin_jobs()
{
   global 
$xoopsTpl;
   ...
   
$xoopsTpl->assign('form1'$form1);
   
$xoopsTpl->display('db:admin/dlinstallx_admin_form1.html');
}

12
phillipd
Re: Using forms in functions
  • 2005/4/3 17:42

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


OK, I got it working. I thought I needed to include all the XOOPS header stuff but I really didn't. I'm still fuzzy on that subject. All I had to do is:

function myMenu($which) {
global $xoopsDB;
require_once XOOPS_ROOT_PATH."/class/template.php";
$xoopsTpl = new XoopsTpl;
require XOOPS_ROOT_PATH."/class/xoopsformloader.php";

$form = new XoopsThemeForm("", "buttonmenuform", "index.php");
//
// Read the menu options from the db and make an array of associative arrays (idx)
// then shove the array into a template container for use by a template script
//
$sql = 'SELECT id,label,op,file,template, title
FROM '.$xoopsDB->prefix('bdr_buttons').'
WHERE grp = '.$which.'
ORDER BY id';
$result = $xoopsDB->query($sql);
$i = 0;
$row = array();
$idx = array();
while(list($id,$label,$op,$file,$template, $title) = $xoopsDB->fetchRow($result)) {
$row['label'] = $label;
$row['op'] = $op;
$row['source'] = $file;
$idx[$i] = $row;
$i++;
$xoopsOption['template_main'] = $template;
$xoopsTpl->assign('title',$title);
}
$xoopsTpl->append('idx',$idx);

$form->assign($xoopsTpl);
$xoopsTpl->display('db:'.$xoopsOption['template_main']);
}

Thanks for the ideas that led me here...

Doug P

Login

Who's Online

302 user(s) are online (253 user(s) are browsing Support Forums)


Members: 0


Guests: 302


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits