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

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 36 total)
  • Author
    Posts
  • #78301

    Well it looks great, but it looks like they are using as1/as2 in this article. I did find several other things but my main area of concern is getting jquery to rename attributes in multiple html tags.

    //edit

    I did find this:

    but I need to know how to title them sequentially
    ie. title1, title2, title3, etc.

    #78303
    Capt Otis
    Member

    The only way can think of are to add another tag with an id/position number for your reference. Then after every change they make, save. Otherwise you need to go into extreme detail and a fair bit of coding to determine what exactly the user is doing and when…. I’ll think about it and let you know if I come up with anything.

    #78305

    well maybe i could put it all in a ul then each group of fields would be in its own li. isnt there an nth something or other? jquery could detect the li position and then place that number after "title"

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

    #78354
    Capt Otis
    Member

    So when the user submits the page, you will be sending every single variable to the next page to be written to the xml… which is why you need a dynamic variable…

    Look up creating a session with php, making that an array, and using it to pass.

    http://www.phpriot.com/articles/intro-php-sessions/7

    Get that working well, and I will help you write the xml file.

    #78356

    Ok here is what I have found:

    Instead of giving the nam attribute, title0, title1, title2, title3, etc.
    I gave it, title[0], title[1], title[2], title[3], etc. and the same for pricing and description.

    So that automatically puts it into an array. So when I click submit on my form it goes to a php file:

    Code:
    “;
    }
    $price = $_POST[‘price’];
    foreach ($price as $p) {
    echo “$p
    “;
    }
    $description = $_POST[‘description’];
    foreach ($description as $d) {
    echo “$d
    “;
    }
    ?>

    and the output is:
    Package 1
    Package 2
    Package 3
    Package 4
    Package 5
    $750
    $1250
    $1750
    $2000
    $3000
    This is a description for Package 1.
    This is a description for Package 2.
    This is a description for Package 3.
    This is a description for Package 4.
    This is a description for Package 5.

    Its not using sessions, but is this what you were talking about?

    #68846

    I also found that this php

    Code:
    “;
    echo “Title: {$title[$i]}
    “;
    echo “Price: {$price[$i]}
    “;
    echo “Description: {$description[$i]}
    “;
    echo “
    “;

    }

    ?>

    Outputs:

    Package:
    Title: Package 1
    Price: $750
    Description: This is a description for Package 1.

    Package:
    Title: Package 2
    Price: $1250
    Description: This is a description for Package 2.

    Package:
    Title: Package 3
    Price: $1750
    Description: This is a description for Package 3.

    Package:
    Title: Package 4
    Price: $2000
    Description: This is a description for Package 4.

    Package:
    Title: Package 5
    Price: $3000
    Description: This is a description for Package 5.

    #78083
    Capt Otis
    Member

    Perfect. Now here is a quick xml file writer…

    Code:
    formatOutput = true;

    $r = $doc->createElement( “pricing” );//creates $doc->appendChild( $r );

    for( $i = 0, $c = count($title); $i < $c; $i++ ) {//loops through your vars... $b = $doc->createElement( “package” );//creates

    $a1 = $doc->createElement( “title” );//creates <br /> $a1->appendChild($doc->createTextNode( $title[$i] ) );//places $title[$i]’s value into <br /> $b->appendChild( $a1 );//closes

    $a2 = $doc->createElement( “price” );
    $a2->appendChild($doc->createTextNode( $price[$i] ) );
    $b->appendChild( $a2 );

    $a3 = $doc->createElement( “description” );
    $a3->appendChild($doc->createTextNode( $description[$i] ) );
    $b->appendChild( $a3 );

    $r->appendChild( $b );//closes }

    $doc->save($xmlLoc);//and save.

    ?>

    I actually didn’t test this, because I don’t want to take the time to set everything up but all looks in order. I commented out so you can see what I did, see if you can figure out how things work. Actually simple once you get it. Modify if needed, best of luck.

    #78365

    I got the following error:

    Warning: DOMDocument::save([path]/pricing.xml) [domdocument.save]: failed to open stream: HTTP wrapper does not support writeable connections in /[path]/submit-pricing.php on line 35

    Warning: DOMDocument::save([path]/pricing.xml) [domdocument.save]: failed to open stream: HTTP wrapper does not support writeable connections in /[path]/submit-pricing.php on line 35

    line 35: $doc->save( $xmlLoc );

    I set the chmod to 777 so i dont know what is wrong

    #78369
    Capt Otis
    Member

    There needs to be an xml file already on your server with the name you changed $xmlLoc to, and in the correct directory. Do you have that?

    #78411

    yes there is.

    #78413
    Capt Otis
    Member

    http://www.dmcinsights.com/phorum/read.php?5,3275

    Make sure your xmlLoc is relative…

    #78414

    It works. Ok now, do you know of a way to execute that inside the current page so I don’t end up in a blank page?

    Can I put that php in the page with my form? Then I could append some html at the bottom that says that the XML was updated successfully.

    #78573
    Capt Otis
    Member

    Here’s how I would do that…

    Place the xml file writing script at the top of your page. Then wrap it in an if statement, to check if the user has submitted the form. Also check your form sends to itself.

    Then you can change the saving file to this…

    Code:
    if ($doc->save($xmlLoc)){
    $varName = ‘You have saved successfully… blah blah’;
    } else {
    $varName = ‘An error has occurred’.
    }

    Then echo $varName where ever you want on the page if it isset().

    #78575

    Ok so I set me form to: action="<?php echo $_SERVER; ?>" but the problem is that it goes here:
    http://www.condiffphotography.com/new/w … /admin.php

    when it should go here:
    http://www.condiffphotography.com/new/w … php?page=3

    It’s probably because it’s inside the wordpress admin. Are there any other ways of calling the processing script at the top?

    Thanks.

Viewing 15 posts - 16 through 30 (of 36 total)
  • The forum ‘Back End’ is closed to new topics and replies.