Jump to content

creating xml from form


Marcel Epp
 Share

Recommended Posts

Hi,

i need some help to create xml files from my upload form. For the form i used Soma's excellent example:

https://gist.github.com/somatonic/5233338

i modified it. I only have an email field and the upload. I don't erase the files in my tmp folder.

What i want is to create xml files with the same name. The same name that my files have.

Example:

photo1.png

photo2.png

photo1.xml

photo2.xml

....

i tried this code but i get stuck where i have to submit the entry from my email field.


// remove extension from filename
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $files);

// create xml for switch

$doc = new DOMDocument('1.0');
$doc->formatOutput = true;

$root = $doc->createElement('phpemail');
$root = $doc->appendChild($root);

$email = $doc->createElement('email');
$email = $root->appendChild($email);

$text = $doc->createTextNode($form_fields);
$text = $email->appendChild($text);

$doc->save($upload_path . $withoutExt . ".xml");
Link to comment
Share on other sites

Hello dragan,

thanks for your answer. It sound silly, but sometimes all i need is little help. You are right.

I removed the extension and did a foreach on that array. This works for me:

// create XML files for switch

            // remove extension from files
            $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $files);
            
            foreach($withoutExt as $withoutExt_string) { 

            $doc = new DOMDocument('1.0');
            // we want a nice output
            $doc->formatOutput = true;

            $root = $doc->createElement('phpemail');
            $root = $doc->appendChild($root);

            $email = $doc->createElement('email');
            $email = $root->appendChild($email);

            $text = $doc->createTextNode(($form_fields ["email"]["value"]));
            $text = $email->appendChild($text);

            $doc->save($upload_path . $withoutExt_string . ".xml");
            
            }

To get the email value i used var_dump to go trough the array.

$text = $doc->createTextNode(($form_fields ["email"]["value"]));
Link to comment
Share on other sites

  • 8 months later...

@Pravin

Hi Pravin,

it's been a while since i played with processwire... My setup was a little bit confusing. I ended up having three files.

As i look trough my files. When you have managed the upload, you probably have some sort of files array.

In my files i used some part of wire upload i think.

// RC: create temp path if it isn't there already
        if(!is_dir($upload_path)) {
            if(!wireMkdir($upload_path)) throw new WireException("No upload path!");
        }

        // setup new wire upload
        $u = new WireUpload('file');
        $u->setMaxFiles($max_files);
        $u->setMaxFileSize($max_upload_size);
        $u->setOverwrite($overwrite);
        $u->setDestinationPath($upload_path);
        $u->setValidExtensions($file_extensions);

        // start the upload of the files
        $files = $u->execute();

Now i had my "files" array. Then i put my xml code in.

// create XML files for switch

            // remove extension from files
            $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $files);
            
            foreach($withoutExt as $withoutExt_string) { 

            $doc = new DOMDocument('1.0');
            // we want a nice output
            $doc->formatOutput = true;

            $root = $doc->createElement('phpemail');
            $root = $doc->appendChild($root);

            $email = $doc->createElement('email');
            $email = $root->appendChild($email);

            $text = $doc->createTextNode($newemail);
            $text = $email->appendChild($text);

            $doc->save($upload_path . $withoutExt_string . ".xml");
            
            }

hope it helps. :)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...