Page 1 of 1

Referring to Super Global Array in Classes

Posted: Sun Sep 10, 2006 8:12 am
by phppage
I seem to be having some issues when referring to post data array within a class. I am using the class below to echo out inputs within a HTML form. I am trying to create a sticky input however the class dose not see the POST data after a submit. I take it I don't need to declare it as global within the class as it is a super global array?

Code: Select all

class textinput {
 var $name;
 var $label;
 var $size;
 var $maxsize;
 var $value;
 var $nobr;

 
 function display( ) {
  $this->findvalue( );
  $this->findmaxsize( );
  $this->arrange( );
 }
 
 function arrange( ) {
  echo "<label for=\"" . $this->name . "\">" . $this->label . " </label><input type=\"text\" name=\"" . $this->label . "\" size=\"" . $this->size . "\" maxlength=\"" . $this->maxsize . "\" value=\"" . $this->value . "\" />";
  if (!isset($this->nobr)) { echo "<br>"; }
 }

 function findvalue( ) {
   if (isset($_POST[$this->name])) { $this->value = $_POST[$this->name]; } else {
       if(!isset($this->value)) { $this->value = "";  } }
   }
 function findmaxsize( ) {
   if (!isset($this->maxsize)) { $this->maxsize = $this->size; }
 
 }
}
Many Thanks :)

Posted: Sun Sep 10, 2006 8:18 am
by feyd
Your class doesn't really seem to set any of the properties other than "value" and "maxsize." Where's "name," "label," "size" and "nobr" set?

Posted: Sun Sep 10, 2006 8:22 am
by phppage
feyd wrote:Your class doesn't really seem to set any of the properties other than "value" and "maxsize." Where's "name," "label," "size" and "nobr" set?
Sorry Feyd, This well could be a complete hash. Have only being playing about with classes for the last couple of hours. I think I'm setting them when I call them. See below

Code: Select all

$email = new textinput;
$email->name = "email";
$email->label = "Email Address: ";
$email->size = "20";
$email->display( );

Posted: Sun Sep 10, 2006 8:33 am
by feyd
I believe if you check the HTML that this generates you'll find that the form element's name isn't "email" but "Email Address: ".

Posted: Sun Sep 10, 2006 8:37 am
by phppage
Doh! :lol:
Many thanks Feyd. Its always the way when your trying some new. When it goes wrong, always over look the simplest things.

Cheers :)