简体   繁体   中英

Save dynamically created form elements into xml

I'm working to a webserver for a mobile application. I want to create a php page where the user decide by letting them add new form elements with a click of a mouse and then the values of these forms saved into an xml file. I use a function like this for add the forms:

 $('a#add').click(function() {
            $('<p><input type="text" name="items[]" id="' + i + '" value="' + i + '" /><select name="items[]"><option value="1">Light</option><option value="2">Shadow</option></select><a href="#" class="remove"> Remove</a></p>'); 
            i++;        
            return false;
    });

Now how can I save all the values of all the forms into an array? Then I must copy all the values into an xml file with simplexml. Excuse me but I'm a newbie of this language.

Thanks.

EDIT

With this code it pass an array and then on the php page we can store the value of the array into a variable as "$bits = $_POST['items'][0];"

Wrap your code with an <form action="foo.php"> tag. The action value describes to which php-page the form-values get sent after submit.

Within the php-page the values are available in $_GET .

(Also works with method="POST" and $_POST .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM