mdemetri2 Posted September 10, 2009 Share Posted September 10, 2009 Ok, I have been toying with a few ideas for a form, but come to the conclusion that I need to make the form dynamic, in that the number of questions will change depending on the user. So, if I have a series of drop downs, free text boxes which all submit as one record in a MYSQL database, what I want to be able to do is on the form be able to allow the user to click say 'add an other question' and it duplicates the form elements underneath giving them to use the pre-configured dropdowns etc. So they keep adding questions and compeleting and then submit the data. Has anyone seen an example of this or know whether its fairly straight forward to do? even being able to do it for just one field I would be able to work the rest out im sure... Many thanks for your responses in advance!! Quote Link to comment https://forums.phpfreaks.com/topic/173754-form-help-being-able-to-duplicate-form-components/ Share on other sites More sharing options...
gr1zzly Posted September 10, 2009 Share Posted September 10, 2009 Create a function that simply prints the required form fields and call that function every time the 'add question' button is clicked. Something like: function add_form_elements ($vars, $if, $required) { echo "<select name=''>"; # populate 'option' fields from db echo "</select><br />\n"; echo "any additional form elements required"; Maybe auto numbering each form element so that you can keep track of how many results are being read back when the form is submitted! * Note - You could also use javascript to reproduce the form elements if you prefer, not sure if benefits vs php? Quote Link to comment https://forums.phpfreaks.com/topic/173754-form-help-being-able-to-duplicate-form-components/#findComment-916174 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.