dbillings Posted June 22, 2008 Share Posted June 22, 2008 When I execute my create_form in my Form class it omits the first value of my $list array. It should print a select box with the options 1,2,3. Thanks for any help you can give. <?php #Form Class 6/20/08 #Last Edit class Form { var $data; var $input=array(); public function Form ($name, $id, $method, $action) { $this->data['name']= $name; $this->data['id']= $id; $this->data['method']= $method; $this->data['action']= $action; } public function add_Input($label, $name, $id, $type, $value) { $this->input[]= new Text($label, $name, $id, $type, $value); } public function add_Select($label, $name, $id, $option, $default) { $this->input[]= new Select($label, $name, $id, $option, $default); } public function create_Form() { foreach($this->input as $value){ if(get_class($value) == "Select"){ echo "<label>$value->label</label><select name='$value->name' id='$value->id'"; foreach($value->option as $option){ echo "<option value='$option'"; if($value->default == $option){ echo "selected='selected'"; } echo ">$option</option>"; } echo "</select>"; } if(get_class($value) == "Text"){ echo "<label>$value->label</label><input type='$value->type' id='$value->id name='$value->name' value='$value->value'>"; } } } } class Text extends Form { var $label; var $name; var $id; var $type; var $value; public function Text($label, $name, $id, $type, $value) { $this->label= $label; $this->name= $name; $this->id= $id; $this->type= $type; $this->value= $value; } } class Select extends Form { var $label; var $name; var $id; var $option= array(); var $default; public function Select($label, $name, $id, $option, $default) { $this->label= $label; $this->name= $name; $this->id= $id; $this->option= $option; $this->default= $default; } } $list= array(1,2,3); $registration_form= new Form("Name", "ID", "post", $_SERVER['PHP_SELF']); $registration_form->add_Input("Name", "name", "ID", "text","Name"); $registration_form->add_Input("Age", "age", "ID", "text","Age"); $registration_form->add_Select("Select", "test", "ID", $list, 1); $registration_form->create_Form(); ?> Link to comment https://forums.phpfreaks.com/topic/111390-solved-my-array-omits-the-first-value/ Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 So is this actually solved? =/ Anyway, why are you using old constructors and no visibility keywords? =/ Also, you shouldn't have the Text, Select, etc. classes extend Form. You should actually have an Element class which can be extended by those form elements. Link to comment https://forums.phpfreaks.com/topic/111390-solved-my-array-omits-the-first-value/#findComment-571894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.