Jump to content

Object Oriented Form - Multiple Check Boxes using show_element($name, $title)


Recommended Posts

I am trying to display multiple check boxes for a volunteer form I am putting together. Basically, it asks the user what areas you want to volunteer in, allowing the user select more than one check box.

 

I was successful in doing that with a select option drop down box, only because it was storing the different selections within an array.

 

I imagine I would have to store the different checkboxes within an array, I researched this and noticed I had to use show_element and I still can't piece it together.

 

Thanks!

on the one page have your checkboxes all named the same ie.

do while (whatever) {

  echo "<input type=check value=$var name=\"chkActivity[]\">";

}

 

 

now on your request page put in:

 

$activities = $_POST['chkActivity']

 

all the selected boxes will return their values in an array.

below is copy of code i used for the t shirt selection:

 

////// T-Shirt Size //////
function DF_xfield4 ($v)
{
$flabels = array (array('label'=>'Small','value'=>'Small'),
                   array('label'=>'Medium','value'=>'Medium'),
                   array('label'=>'Large','value'=>'Large'),
                   array('label'=>'X-Large','value'=>'X-Large'),
                   array('label'=>'2X-Large','value'=>'2X-Large'),
                   array('label'=>'3X-Large','value'=>'3X-Large'));

	return array("type"=>"select",
		 "name"=>"D_xfield4",
		 "options"=>$flabels,
		 "size"=>1,
		 "extrahtml"=>$xtra2,
		 "value"=>'$v');
}

 

i want to be able to do the same thing, but i know i can't with modifying this code, for using it for checkboxes, i know the code below won't do the trick, but figured i'd show you, so you could see what i was doing wrong:

 

///// Areas of Interest /////
function DF_xfield1 ($v)
{
$flabels = array (array('name'=>'Childrens Area','value'=>'Childrens Area'),
                   array('name'=>'Retail Sales','value'=>'Retail Sales'),
                   array('name'=>'Info Booth','value'=>'Info Booth'),
                   array('name'=>'Beer/Wine Pouring','value'=>'Beer/Wine Pouring'),
                   array('name'=>'Ticket Takers','value'=>'Ticket Takers'),
                   array('name'=>'Hospitality','value'=>'Hospitality'));

	return array("type"=>"checkbox",
		 		"name"=>"D_xfield1",
		 		//"name"=>$flabels,
		 		"extrahtml"=>$xtra2,
		 		"value"=>'$v');
}

 

this is the of_checkbox.inc file that is on the server, i am not familiar with ooh forms, i was just thrown into it, so i'm trying to figure this checkbox out, and i'm golden:

 

<?PHP
/* OOHForms: checkbox
*
* Copyright (c) 1998 by Jay Bloodworth
*
* Id: of_checkbox.inc,v 1.2 2002/04/28 03:59:32 richardarcher Exp
*/

class of_checkbox extends of_element {

  var $checked;

  // Constructor
  function of_checkbox($a) {
    $this->setup_element($a);
  }

  function self_get($val, $which, &$count) {
    $str = "";

    if ($this->multiple) {
      $n = $this->name . "[]";
      $str .= "<input type=\"checkbox\" name=\"$n\" value=\"$val\"";
      if (is_array($this->value)) {
        reset($this->value);
        while (list($k, $v) = each($this->value)) {
          if ($v==$val) {
            $str .= " checked=\"checked\"";
            break;
          }
        }
      }
    } else {
      $str .= "<input type=\"checkbox\" name=\"$this->name\"";
      $str .= " value=\"$this->value\"";
      if ($this->checked) {
        $str .= " checked=\"checked\"";
      }
    }
    if ($this->extrahtml) {
      $str .= " $this->extrahtml";
    }
    $str .= " />\n";

    $count = 1;
    return $str;
  }

  function self_get_frozen($val, $which, &$count) {
    $str = "";

    $x = 0;
    $t="";
    if ($this->multiple) {
      $n = $this->name . "[]";
      if (is_array($this->value)) {
        reset($this->value);
        while (list($k, $v) = each($this->value)) {
          if ($v==$val) {
          $x = 1;
            $str .= "<input type=\"hidden\" name=\"$this->name\" value=\"$v\" />\n";
            $t =" bgcolor=\"#333333\"";
            break;
          }
        }
      }
    } else {
      if ($this->checked) {
        $x = 1;
        $t = " bgcolor=\"#333333\"";
        $str .= "<input type=\"hidden\" name=\"$this->name\"";
        $str .= " value=\"$this->value\" />";
      }
    }
    $str .= "<table$t border=1><tr><td>&nbsp</td></tr></table>\n";

    $count = $x;
    return $str;
  }

  function self_load_defaults($val) {
    if ($this->multiple) {
      $this->value = $val;
    } elseif (isset($val) && (!$this->value || $val==$this->value)) {
      $this->checked=1;
    } else {
      $this->checked=0;
    }
  }

} // end CHECKBOX

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.