Jump to content

Form help - being able to duplicate form components


Recommended Posts

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!!

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.