PHP/JS integration question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

PHP/JS integration question

Post by mattcooper »

Hello again.

Below is some JScript that creates new form elements (Thanks for the tip, Feyd, this was the right way to do it in the end!). When I submit the page, the contents of the textfields will be used to construct buttons on a preview page. Eventually, the contents will end up in a database.

Code: Select all

function addT(){
var root = document.getElementById('container');
var j=root.getElementsByTagName('div').length+1;
var clone = root.getElementsByTagName('div')[0].cloneNode(true);
var txt=clone.getElementsByTagName('input');
txt[0].name='link'+j;txt[0].value='URL';
txt[1].name='label'+j;txt[1].value='label';
root.appendChild(clone)
}
I am having a problem envisaging how to get this to happen. For example, the user creates three sets of textfields and submits them to the form handler - how, then, does the form handler deal with the $_POST information if it doesn't know how many sets of textfields are coming? I'm guessing that the solution would be an array, but those of you who are familiar with older posts from me will know that I'm crap with arrays!

Any suggestions would be greatly appreciated!

Thanks in advance :)
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

Thanks - it works for the entire form except for the JS-generated elements - it only dumps data for the last form element created and misses the others. Since my understanding of arrays is soooo bad, can somebody please tell me why this is happening??

Thanks again!
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

Whoops, it was a JS error not a PHP one... all is well on that front now. Any hints on insertion of the resultant fields into the database? Similar problem, I expect, with a similar solution?
Post Reply