- This topic is empty.
-
AuthorPosts
-
June 21, 2010 at 2:12 pm #78301Historical Forums UserParticipant
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:
Code:$(‘input.title[name]’).each(function() {/* create a jquery object from the DOM object */
var $input_with_name = $(this);/* add the new attribute with the title value */
$input_with_name.attr(“newNameAttribute”, $input_with_name.getAttribute(‘name’));/* remove the old attribute */
$input_with_name.removeAttr(‘name’);});
but I need to know how to title them sequentially
ie. title1, title2, title3, etc.June 21, 2010 at 2:25 pm #78303Capt OtisMemberThe 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.
June 21, 2010 at 2:34 pm #78305Historical Forums UserParticipantwell 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"
June 21, 2010 at 11:47 pm #78327Historical Forums UserParticipantJust 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.htmlcan you help me to make sense of it?
thanks.
June 22, 2010 at 11:39 am #78354Capt OtisMemberSo 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.
June 22, 2010 at 12:21 pm #78356Historical Forums UserParticipantOk 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?
June 22, 2010 at 12:36 pm #68846Historical Forums UserParticipantI 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.June 22, 2010 at 2:19 pm #78083Capt OtisMemberPerfect. 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
$a1->appendChild($doc->createTextNode( $title[$i] ) );//places $title[$i]’s value into
$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.
June 22, 2010 at 2:58 pm #78365Historical Forums UserParticipantI 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
June 22, 2010 at 3:41 pm #78369Capt OtisMemberThere 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?
June 22, 2010 at 4:00 pm #78411Historical Forums UserParticipantyes there is.
June 22, 2010 at 4:10 pm #78413Capt OtisMemberhttp://www.dmcinsights.com/phorum/read.php?5,3275
Make sure your xmlLoc is relative…
June 22, 2010 at 4:28 pm #78414Historical Forums UserParticipantIt 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.
June 23, 2010 at 10:16 am #78573Capt OtisMemberHere’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().
June 23, 2010 at 11:16 am #78575Historical Forums UserParticipantOk 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.phpwhen it should go here:
http://www.condiffphotography.com/new/w … php?page=3It’s probably because it’s inside the wordpress admin. Are there any other ways of calling the processing script at the top?
Thanks.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.