Jump to content
Sign in to follow this  
drisate

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"?>

<data>
    <debug>1</debug>
	<db>
		<host>localhost</host>
		<user>***</user>
		<pass>***</pass>
		<name>***</name>
	</db>
	<config>
		<path_to_site>***:81</path_to_site>
		<path_to_movies>media</path_to_movies>
		<full_path_to_movies>/var/www/media/movies/</full_path_to_movies>
		<full_path_to_shows>/var/www/media/shows/</full_path_to_shows>
		<tmdb_api_key>***</tmdb_api_key>
		<lang_api_key>***</lang_api_key>
		<tvdb_api_key>***</tvdb_api_key>
		<allowed_movie_ext>
			<ext>mp4</ext>
			<ext>m4v</ext>
		</allowed_movie_ext>
		<delete_skiped>1</delete_skiped>
		<system>linux</system>
		<lastmovies>25</lastmovies>
		<language>en</language>
		<country>US</country>
		<debug>0</debug>
		<junk>
			<word>1080p</word>
			<word>BluRay</word>
			<word>x264</word>
			<word>YIFY</word>
			<word>YIFY</word>
			<word>BrRip</word>
			<word>BOKUTOX</word>
			<word>YIF</word>
			<word>bitloks</word>
			<word>deceit</word>
			<word>BrRip</word>
			<word> GAZ</word>
			<word>GAZ</word>
			<word>UNRATED</word>
			<word>ECE</word>
			<word>mkv</word>
			<word>DVDSCR</word>
			<word>XViD</word>
			<word>FRENCH</word>
			<word>TS</word>
			<word>MD</word>
			<word>SKuLL322</word>
			<word>DTS</word>
			<word>Multi</word>
			<word>bluray</word>
			<word>net</word>
			<word>torrentfrancais</word>
			<word>truefrench</word>
			<word>5.1</word>
			<word>\xb7</word>
		</junk>
		<user_lang>
			<lang>en</lang>
			<lang>fr</lang>
			<lang>es</lang>
		</user_lang>
	</config>
	<hdd>
		<path>
			<torrent_path>/var/Simflix/scripts/addons/torrent/</torrent_path>
			<temp_path>/var/Simflix/scripts/addons/temp/</temp_path>
			<save_path>/mnt/My Book 4/media/series temp/</save_path>
		</path>
		<path>
			<torrent_path>/var/Simflix/scripts/addons/rss_download/torrents/</torrent_path>
			<temp_path>/var/Simflix/scripts/addons/temp/</temp_path>
			<save_path>/mnt/My Book 4/media/movies temp/</save_path>
		</path>
	</hdd>
</data>

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"/>
        </div>
     </div>
    ');
}
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"/>
        </div>
     </div>
    ');
}

$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);
        }
    }else{
        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.

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.

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.