Multiple forms

Discussion in 'JavaScript' started by Sipifi, Jun 11, 2008.

  1. #1
    Hello,

    I'm currently working on a new page in php to submit proxies and i'd love an option to add more forms so people can submit more than one proxy at a time.
    I'm guessing it isn't much more different than a file upload form with the option to add more files.

    I have no idea where to start and was hoping that someone could point me in the right way.

    Regards

    /Sipifi
     
    Sipifi, Jun 11, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I guess you don't need several forms, but several input fields all submitted together in one form. I'd do that with something like that:
    
    <script type='text/javascript'>
    function addField()
    {
    	//get the value from the text box
    	var value = document.getElementById('newValue').value;
    
    	//create a new <li> element which will be added to the list
    	var li = document.createElement('li');
    	
    	//create a text field which will show the entered values and submit them with the form
    	//you can use any kind of element to do that...
    	var textField = document.createElement('input');
    	textField.type = 'text';
    	textField.name = 'fields';
    	textField.value = value;
    	textField.readOnly = true;
    	
    	//append our text field to the list item
    	li.appendChild(textField);
    	
    	//now append the list item with the text field in it to the list
    	document.getElementById('myList').appendChild(li);
    	
    	//clear the old value from the input field
    	document.getElementById('newValue').value = '';
    }
    </script>
    
    <form method='post'>
    <ul id='myList' style='list-style: none'><li><input type='text' id='newValue'><input type='button' onclick='addField()' value='Add'></li></ul>
    
    <input type='submit' value='Submit'>
    </form>
    
    <?
    var_dump($_POST['fields']);
    ?>
    Code (markup):
     
    xlcho, Jun 11, 2008 IP