Jump to content

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']}'>";

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.