11
phillipd
Re: Is there a way to...
  • 2004/11/11 21:43

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I seem to have a more fundamental problem now. I'm using Smarty in an "admin" script and my Buttons aren't submitting a "op" to my recieving script, which is actually the same as my form script. Nothing in the "op == submit" block ever gets executed and "op" never = "submit". This must be why no one uses smarty in admin scripts??? Am I missing an include somewhere?

include '../../../mainfile.php';
include '../../../include/cp_header.php';
include "../language/english/main.php";

if ( isset($HTTP_POST_VARS['op']) && $HTTP_POST_VARS['op'] == "submit" ) {
$op = "submit";
echo "Setting op to submit";
}
if ( isset($HTTP_POST_VARS['op']) && $HTTP_POST_VARS['op'] == "form" ) {
$op = "form";
echo "Setting op to form";
}


if ( $op == "form" ) {
xoops_cp_header();
require_once SMARTY_DIR.'Smarty.class.php';
$xoopsTpl = new Smarty;
$xoopsOption['template_main'] = 'ecngis_admin.html';
include XOOPS_ROOT_PATH."/header.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";

#
# Fill in the select gadget
#
$select_defaults = new XoopsFormSelect("","defaults","","10",true);
$tray_defaults = new XoopsFormElementTray(_MM_LAYERS, " ");

$sql = 'SELECT id,status,name FROM '.$xoopsDB->prefix('gis_layers').' ORDER BY id';
$result = $xoopsDB->query($sql);

while(list($id,$status,$name) = $xoopsDB->fetchRow($result)) {
$select_defaults->addOption($id,$name);
if($status) {
$select_defaults->setValue($id);
}
}

$tray_defaults->addElement($select_defaults);

$op_submit = new XoopsFormHidden("op", "submit");
$submit_button = new XoopsFormButton("", "", "Set as Default", "submit");

$form = new XoopsThemeForm("", "layerform", "setlayers.php");

$form->addElement($tray_defaults);
$form->addElement($submit_button);
$form->addElement($op_submit);

$form->assign($xoopsTpl);
$xoopsTpl->assign('lang_layers', _MM_LAYERS);

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

if ( $op == "submit" ) {
xoops_cp_header();
require_once SMARTY_DIR.'Smarty.class.php';
$xoopsTpl = new Smarty;
$xoopsOption['template_main'] = 'ecngis_admin.html';
include XOOPS_ROOT_PATH."/header.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";

$layers = "";
echo "2222222222222222222222222222222222222222222222222";
$defaults = $_POST['select_defaults'];
foreach ( $defaults as $key => $val) {
echo "-----$key,$val";
}
}

12
phillipd
Re: Is there a way to...
  • 2004/11/12 5:24

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


OK here is the scoop. I can make the select list work, but I don't like it because if the user clicks a list element, all the other selected elements get unselected. They have to hold down the "control" key to prevent this.

I really like the checkboxes better but when I put them in the tray and form in the manner you suggest, they look very messy, not nicely formatted in rows and columns. And, are they a single checkbox with multiple "options". How do you nicely format multiple gadgets placed in the same tray?

In order to nicely format them, I use arrays of trays, and checkboxes like this:

$form = new XoopsThemeForm("", "layerform", "setlayers.php");
$check = array();
while(list($id,$status,$name) = $xoopsDB->fetchRow($result)) {
$tray[$i] = new XoopsFormElementTray("");
$check[$i] = new XoopsFormCheckBox("",$name);
$check[$i]->addOption($id,$name);
if($status) {
$check[$i]->setValue($id);
}
$tray[$i]->addElement($check[$i]);
$form->addElement($tray[$i]);
}

But then they are separate elements and I can't programatically get at them in the recieving script. How can I send this array of individual checkboxes to my recieving script?

Thanks again...

Doug P

13
phillipd
Re: Is there a way to...
  • 2004/11/12 5:41

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


AHHHH! I finally got it to work! I use:

$i = 0;
while(list($id,$status,$name) = $xoopsDB->fetchRow($result)) {
$tray[$i] = new XoopsFormElementTray("");
$check[$i] = new XoopsFormCheckBox("",$name);
$check[$i]->addOption($id,$name);
if($status) {
$check[$i]->setValue($id);
}
$tray[$i]->addElement($check[$i]);
$form->addElement($tray[$i]);
$i++;
}

---------------------------------------------------------
Then to receive the checkboxes that are selected, I use:

$sql = 'SELECT id,status,name FROM '.$xoopsDB->prefix('gis_layers').' ORDER BY id';
$result = $xoopsDB->query($sql);
while(list($id,$status,$name) = $xoopsDB->fetchRow($result)) {
if(!empty($_POST[$name]) && $_POST[$name] > 0) {
echo "Got $name!
";
}
}


Thanks for all your time and your wonderful ideas!

Regards

Doug P

Login

Who's Online

206 user(s) are online (129 user(s) are browsing Support Forums)


Members: 0


Guests: 206


more...

Donat-O-Meter

Stats
Goal: AU$15.00
Due Date: Jul 31
Gross Amount: AU$0.00
Net Balance: AU$0.00
Left to go: AU$15.00
Make donations with PayPal!

Latest GitHub Commits