Jump to content

[SOLVED] SimpleXMLElement object property as key


milnet

Recommended Posts

I have a class that reads an xml file with simplexml and it tries to get a $_POST variable based off a value in the xml file. It keeps giving me warning "Illegal offset type." I have tried multiple things to fix it but I just can't figure it out. Any help would be greatly appreciated.

 

function submitform(){

if($this->xml->formprocess->contact){

echo $this->xml->formprocess->contact->firstname;

echo $_POST[$this->xml->formprocess->contact->firstname];

 

}

 

}

 

 

Yeah here is some more. Sorry.

 

class xmlform {
var $mainid;
var $contentid;
var $formlabel;
var $formdesc;
var $inputstring;
var $xml;
function __construct($xmlfile){
	if(file_exists($xmlfile)){
		$this->xml = new SimpleXMLElement($xmlfile, NULL, TRUE);		
	}
	else {
		die('xml fail');
	}
	if(!$_POST['submit']){
		$this->makeform();			
		include("forms/formtemp.php");
	}
	else{
		$this->submitform();
		//include("forms/formthankyou.php");
	}
}

function makeform(){...
          ...											
}

function submitform(){


	$cw = new contactwisesession();
	if($this->xml->formprocess->contact){
		echo $this->xml->formprocess->contact->firstname;
	        echo $_POST[$this->xml->formprocess->contact->firstname];			
	}

}




}

 

This is the line that is giving me trouble:         echo $_POST[$this->xml->formprocess->contact->firstname];

please use code tags next time...

try:

if($this->xml->formprocess->contact){
         echo $this->xml->formprocess->contact->firstname;
	 $firstname = (string)$this->xml->formprocess->contact->firstname;
              echo $_POST[$firstname];         
      }

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.