We help IT Professionals succeed at work.

Edit form

savsoft
savsoft asked
on
I am designing project .. I want to create my sign up form dynamically. Admin can add fields and field type from admin panel to design sign up form and their respective column where data should store...

So I need any idea or logic ... how to do it....

Please
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Why don't you use 1 field for questions and one for answers and serialize the input that way you don't have to build the fields on the fly.

Or have. A table sign-up questions and run through that to get a form.
What you are asking for is a somewhat complex thing to do.  We wrote a .NET app that utilizes dynamic data on many of its forms.  Rendering the form, saving inputs, printing reports is all a bit of a challenge.



One way to do it is to build a table of form fields that have at least the following characteristics:

fieldID - primary key
formID - who/what form the field is associated with
formLabel - field label text
dataType - what kind of data is expected (int, string, etc.)
formRender - what kind of field do you render on the form (text, textarea, etc.)
displayOrder - when you build the form what order do the fields get rendered in

You would have a table of user_formData that stores the responses for each user.  It would have:

userFormID - primary key
userID - the user who completed the form
fieldID - the field that is being completed
fieldValue - the data the user entered


That should give you the ability to collect the data for each user as they sign-up.

Things to think about:

1. How would you handle checkboxes / radio buttons, etc. that could have multiple defined choices?  Perhaps in your form fields table you have another field that includes the option values with a delimiter such as Yes|No|Maybe|Never and then your code blows that out into a list of radio buttons

2. How many different forms and fields will you have.  There could be performance implications in generating and rendering the form. If the forms will be used frequently you may want to have the admin process generate a static version of the form each time you make a change to it as opposed to having the system build the form dynamically each time it is requested.  We saw a huge performance improvement by doing this.

Hope this is helpful...




Author

Commented:
Ya its lil bit help ful. I have got the idea that how to develop such system. But please make this thing clear to me..

I need a bit more elaboration in this.... If You can please.........
You have two groups of people affecting your work: admins and users. Both need data to be stored some place, and database is one choice (best in my opinion, so let's stay with it).

to put it simply:

You have to create a table which will store your form fields. This is to be done in database because we assume, you will be adding and disabling/enabling those field on the go (admin).

smadeira's design is very good for that purpose.

I don't advise removing or changing fields because you risk your historical data inputs (users) to go out of sync.

You would associate your form field types with database dataType field.

string, number, boolean, select, checkbox, text

The reason to mix form and actual types names here is to make it easier to find out what do you store there and how to display it. Both number and strong would need a text input field, with name coming from fieldName database field.:

<input type="text" name="fieldName">

boolean would be displayed as radio element, text as textarea I'm sure you follow that logic.

You may need four additional field in that database design:

fieldName - to name somehow the field variable
isMandatory - to mark field which have to be filled in.
fieldCheck - with description on how to check that file, preg definition for example. you may want to test your emails and so on. This needs a bit more thinking. But you can assume that all text fields should be stripped of code, and all select fields should have options defined
defaultValue - pretty self explanatory for all fields, except select field where you would have to store options here.

In other words:

Admin logs in, choses to create:

fieldID - populated automatically
formID - email
fieldName - emailorsms
formLabel - Do you want us to respond by email or sms?
dataType - checkbox
displayOrder - 1000 (to ensure it's displayed as last)
isMandatory - 0 (as a negative answer)
fieldCheck - <empty>
defaultValue - Email|SMS

This then would be displayed as (assuming other fields already were in the database)::

 <form action="..." method="post" id="email">
    First name: <input type="text" name="firstname"><br />
    Last name: <input type="text" name="lastname"><br />
    Email: <input type="text" name="email"><br />
    Phone number: <input type="text" name="phone"><br />
    Message: <textarea name="message" rows="20" cols="80"></textarea>

Do you want us to respond by email or sms?
<input name="emailorsms"  type="checkbox" value="email">Email
<input name="emailorsms"  type="checkbox" value="sms">SMS

    <input type="submit" value="Send"> <input type="reset">
 </form>

Explore More ContentExplore courses, solutions, and other research materials related to this topic.