Jump to content

[SOLVED] Index getting lost PHP 4


dbillings

Recommended Posts

I'm setting up my class variables as an array ($text['label'], $text['type'] etc...). Then I'm creating the object in another class and saving the object to another array $input. When I loop through the $input array the object prints...

<label>Array['label']</label><input type='Array['type']'
		id='Array['id]' name='Array['name']' value='Array['value']'><label>Array['label']</label><input type='Array['type']'
		id='Array['id]' name='Array['name']' value='Array['value']'> 

 

It doesn't seem to recognize my assciative indexs I created. Any ideas why?

 

Here's the full code

 

<?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 create_Form() 
{

	foreach($this->input as $value){

		echo "<label>$value->text['label']</label><input type='$value->text['type']'
		id='$value->text['id]' name='$value->text['name']' value='$value->text['value']'>";
	}
}
}

Class Text extends Form
{
var $text;

public function Text($label, $name, $id, $type, $value)
{
	$this->text['label']= $label;
	$this->text['name']= $name;
	$this->text['id']= $id;
	$this->text['type']= $type;
	$this->text['value']= $value;

}
}



$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->create_Form();

?>

Link to comment
https://forums.phpfreaks.com/topic/111381-solved-index-getting-lost-php-4/
Share on other sites

Try changing...

 

echo "<label>$value->text['label']</label><input type='$value->text['type']'

id='$value->text['id]' name='$value->text['name']' value='$value->text['value']'>";

 

To

 

echo "<label>{$value->text['label']}</label><input type='{$value->text['type']}'

id='{$value->text['id]}' name='{$value->text['name']}' value='{$value->text['value']}'>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.