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];

 

}

 

}

 

 

Link to comment
Share on other sites

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];

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.