Jump to content
Sign in to follow this  

XML array to HTML form

Recommended Posts

Hey guys, i have an XML file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>

			<word> GAZ</word>
			<save_path>/mnt/My Book 4/media/series temp/</save_path>
			<save_path>/mnt/My Book 4/media/movies temp/</save_path>

I use that XML data in my website like this:

$config = simplexml_load_file('/var/Simflix/www/config.xml');

It working great but now i need to create a code that would edit that XML file ...


So fare i manager to do this:


function print_input($name, $value){
    print ('
	<div class="formRow">
        <label>'.ucfirst($name).': </label>
        <div class="formRight">
             <input id="name" name="'.$name.'" value="'.$value.'" class="span input" type="text"/>
function print_input_array($name, $value, $title){
    $rand = rand("999999999", "999999999999");
    print ('
	<div class="formRow">
        <label><span class="addmore" name="'.$name.'" rel="g'.$rand.'" style="cursor:pointer">(ADD)</span> '.ucfirst($title).': </label>
        <div id="g'.$rand.'" class="formRight">
             <input id="name" name="'.$name.'[]" value="'.$value.'" class="span input" type="text"/>

$config_array = get_object_vars($config);

foreach($config_array[db] as $name=>$value){
    print_input($name, $value);

foreach($config_array[config] as $name=>$value){
    if (is_array($value)){
        foreach($value as $name1=>$value1){
            print_input_array($name1, $value1, $name);
        print_input($name, $value);

But for some reason, the print_input_array() is not triggured when i get to the allowed_movie_ext, junk, user_lang [...]


Is there a better way of making an HTML form from a XML object?

Edited by drisate

Share this post

Link to post
Share on other sites

$value is never an array. It's always a SimpleXMLElement object. Even if the XML node does not have children.


Try count()ing to see how many children the element has.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

Sign in to follow this  

  • 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.