Forums / Developer / Saving ezxmltext through ajax

Saving ezxmltext through ajax

Author Message

Sao Tavi

Thursday 16 June 2011 12:37:16 pm

I tried to create something like an autosave feature for an ezxmltext, but I soon found out that it is not that easy to save the new data into the db in the correct format. I tried looking at ezxmltext datatype for getting help, but after several hours I gave up.

So... if I have in php the contents from a tiny mce editor and the contentObjectAttribute, how can I save them into the database in the right format?

What I did was either stripping the images or a lot of other things that were not right.

 

Oh, and just as a note: something strange happened, when trying to add images to the xml text I was getting some errors (like 'ez publish "A file is required for upload, no file were found.  No HTTP file found, cannot fetch uploaded file.') . Trying to find out the problems origins, without changing anything, it magically solved by itself after several tries and checking this on another ez publish install on the same server... Unfortunately, I cannot reproduce it.

PS: The redirection system is not good when using multiple tabs on the same ez publish installation. Maybe it should use post variables instead of cookies? I believe I should post this in the issues tracker.

Sao Tavi

Thursday 16 June 2011 2:54:24 pm

With a little bit of help, I found the answer eventually. It seems that I needed to use the parser from ezoe, it works with no problems now.

Here is the code used:

 

                $parser = new eZOEInputParser( );
                $parser->setParseLineBreaks( true );
                 
                if (!$document = $parser->process( $http->postVariable('val') ))
                    return 'failed to parse';
                 
                // Create XML structure
                $xmlString = eZXMLTextType::domString( $document );              

                $options['description']->setAttribute('data_text', $xmlString);
                $options['description']->store();