joaogl Posted November 5, 2014 Share Posted November 5, 2014 Hello, I'd like to know how could I make a form with infinite elements and send it to mysql. Example: <div class="templatemo-input-icon-container"> <i class="fa fa-info-circle"></i> <input type="text" class="form-control" id="name" name="sname" value="<? echo $dataname; ?>" placeholder="Person name"> </div> I have this code which I can very easily put to work and send the sname value to a mysql database. My problem now is that I don't know how many persons the user whats to add, for that reason I'd like to add a button called Add Person, and if the user clicks it, it will appear like a new copy of this div. I've seen on the google that I can use HTML DOM createElement() to create this textboxes, but, if I do, how can I get their values if I don't know their name's or id's etc? and also how could I create an Element with classes? PS: I'd like to make this without having to reload the page. Thanks, Joao Lourenco. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 5, 2014 Share Posted November 5, 2014 Assuming that you don't want the page to reload every time the "Add Person" button is clicked, this is more of a JavaScript question. Are you familiar with JavaScript...or something like jQuery? Here is a quick jQuery script which seems to do what you are asking: http://jsfiddle.net/jaredwilli/tZPg4/4/ In case it helps, here is the Google search I used to find the above code: https://www.google.com/search?q=javascript%20add%20more%20input%20fields Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 5, 2014 Share Posted November 5, 2014 and to get the data from dynamically created form fields, the field name needs to be an array - http://us1.php.net/html#faq.html.arrays so that the data can be processed as an array in the php code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.