Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Edit XML with PHP Re: Edit XML with PHP

#78327

Just a fyi, I figured out how to re-name my attributes dynamically, even after the user adds and/or removes field groups.

This is my jQuery:

Code:

function renameAttr(){
$(“input.title”).attr(“name”, function (arr) {
var $t = $(this);
$t.removeAttr(‘name’);
return “title” + arr;
});
$(“input.price”).attr(“name”, function (arr) {
var $t = $(this);
$t.removeAttr(‘name’);
return “price” + arr;
});
$(“textarea.description”).attr(“name”, function (arr) {
var $t = $(this);
$t.removeAttr(‘name’);
return “description” + arr;
});
};
renameAttr();
function addPackage(){
$(“.metabox-holder”).append(‘

Package

‘);

renameAttr();

$(‘.remove:button’).click(function(){
$(this).parents(‘[class*=postbox]:first’).remove();
renameAttr();
});
}
$(‘.remove:button’).click(function(){
$(this).parents(‘[class*=postbox]:first’).remove();
renameAttr();
});

Now I just need to figure out how to save the XML using that script you gave me earlier. It would somehow have to detect the number of field groups…or erase all the values altogether and replace them with the new values in the form.

It would have to go like this:

Make and Loop through form array / detect number of field groups
for each:
add element "package"
add element "title"
get text from field with attribute name=" "title" + "#" "
close element "title"
add element "price"
get text from field with attribute name=" "price" + "#" "
close element "price"
add element "description"
get text from field with attribute name=" "description" + "#" "
close element "title"
close element "package"

I did find this post though:
http://www.daniweb.com/forums/thread148513.html

can you help me to make sense of it?

thanks.