milnet Posted May 18, 2009 Share Posted May 18, 2009 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 https://forums.phpfreaks.com/topic/158662-solved-simplexmlelement-object-property-as-key/ Share on other sites More sharing options...
Brian W Posted May 18, 2009 Share Posted May 18, 2009 can you post all of the code, it may help us figure out the problem. Link to comment https://forums.phpfreaks.com/topic/158662-solved-simplexmlelement-object-property-as-key/#findComment-836790 Share on other sites More sharing options...
milnet Posted May 19, 2009 Author Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158662-solved-simplexmlelement-object-property-as-key/#findComment-837699 Share on other sites More sharing options...
Brian W Posted May 19, 2009 Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158662-solved-simplexmlelement-object-property-as-key/#findComment-837706 Share on other sites More sharing options...
milnet Posted May 19, 2009 Author Share Posted May 19, 2009 That worked great. Thank you very much! Link to comment https://forums.phpfreaks.com/topic/158662-solved-simplexmlelement-object-property-as-key/#findComment-837708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.