Suppose I got a webform with some fields like "Name, Surname, Address, Phone, Email, Preference, Hobby". What I need now is when a user is filling the form, Suppose he fills the Name field, the data is stored in the sql table, same goes for surname, once surname field is filled now Name and Surname will be saved in the table. The save must be done on the lost focus event of each field. The user can abandon the form filling anytime, even if the form is not completely filled.
The form by default has the status “Abandoned” which is stored in a hidden field, but once all fields in the form have been completely filled, this status should change to “Processed”.
Can anyone please suggest or get me an example of how this can be done?
You can implement this logic:
Add additional field in database for session ID
On lost focus, call ajax to update DB's field and you can check
record with session ID field.
you can also check using PHP for all fields' value to identify record
status instead of javascript update in hidden field
Related
I have 2 forms, each one is on a different page, and they both fill information in the same table in the database. Whenever I try to fill them up, the database displays the information as 2 entries, how I can I display the information in the same row in mysqli?
(first form asks the user to submit first name and last name, second form asks him to submit email and phone number) putting them in one form is not an option.
I have two forms in the same page, the first form will have email, name, password etc.
In a second form there are qualification, skills, institution etc.
I will add data from the first form into one table. I want to take the ID of the data from the first form and add qualifications, skills and institution in another table along with the ID from the first form.
I am doing this in php. Please give me an idea how to implement this.
try to do it with Ajax
User enters email, pass..etc, and clicks submit button after that trigger Ajax Call with form data. Store the data in your table and return Mysql Last Inserted Id. Store Last Inserted Id in your load JS Variable/HTML Hidden value.
Steps :
- User Enters Details and press Submit button
- Ajax call triggers with your data
- get Last Insert id from back-end(ajax response)
- store id in html hidden value or js variable
- use this details for next form
I'm using the Formidable Pro WordPress plugin to create editable forms. Each form has several different "Contact Info" areas (in the below picture, one such area is "General Contractor", and another one is "Mechanical Engineer"), and each area has several inputs.
What I'm looking to create:
Enter first few letters of persons name in "Contact" input
Select a name from resulting Autocomplete drop-down
Populate nearby fields with Contact's respective information (Company, Email, Phone, Fax, Tax ID, and Address)
The first image below shows two of the "Contact Info" areas (the first of which I drew in each input's ID). The second image shows how each Contact's information is stored in a MySQL table.
So are there any Autocomplete WordPress or jQuery plugins that can help me accomplish this, and if so, how would I go about implementing this feature?
I'm guessing for the drop-downs you're using dynamic fields? Replace these with Lookup fields and then you can automatically populate values of other fields like so:
For each field you want auto-populated, go into the field settings and check the option 'Dynamically retrieve the value from a Lookup field'. Then, for the 'Get value from' options, you'll need to select the form and field you want to Get the data from. Then, for the 'Watch Lookup fields' option you'll need to select the lookup field (which will be your 'Contact' input that users are typing into).
I'm working on an app that lets a user create projects custom to the users needs, the project is basically a form that can be submitted by another user.
I want to allow the user to dynamically create new fields (with Javascript) to the project (a basic form) and choose custom values for each field.
And when the project (the form) is ready it can be submitted and the user specified values goes to a database. Then another user can submit the form and the values the original user has chosen are as options for that form.
The values (that are dynamically created by the user) are most likely going to be basic data, like name, phone, email etc. But there is also options for specific data like food, address, etc. I want the user to be able to ask for any data he/she sees necessary.
So how should I structure my database? I cannot be sure what or how many fields the user is going to choose for his project, i was thinking of doing this app in a traditional relational database, most likely Postgres or Mysql.
So should a create columns for all the data I can think of (or allow user to create) or could this be done in some other way?
You may want to take a look at the EAV model. It has some pros as you will have some flexibility to create whatever structure you want, but it has also some limitations on retrieving and querying afterwards.
Your database should contain the following columns in the table for the form specs:
name (name of the field, used as "name" attrubute of the form's input field)
label (Description to print in the form)
format (if you want to distinguish selects/inputs/checkboxes)
validation (if you want a set of validation rules)
value_type (int/string/date/etc.. - type of value to accept from user. helpful for validation)
I ran into a similar situation with an assessment application. Each assessment asked a number of questions, but periodically, the question set would change. Rather than creating a separate table with key/value pairs for the questions and answers, I took advantage of serializing in PHP.
Determine what data must be a part of every form (Id, submitter, submission datetime, name of project, phone) Make those data elements columns in your table.
Create an additional column for the serialized data. This is where you store the additional attributes.
(Only 1 table needed)
When it comes to displaying the form, use the serialized data to build the additional form elements that are needed.
With this model, it is difficult to search the additional data that gets stored in the serialized data, but it simplifies the development; with thousands of records, and over 100 'questions' per assessment, we haven't run into an issue yet.
One possible option:
table: inputs
Description: Stores different types of inputs (select, select multiple, input, checkbox, radio)
Fields: inputtypeid (primary), input_type, status
table: fields
Description: Stores individual fields that the project owner has created.
Fields: fieldid (primary), inputtypeid (ref inputs), label
table: values
Description: Stores values (default and user submitted) for fields.
Fields: valueid (primary), fieldid (ref fields), value, default (bool yes/no)
table: project_forms
Description: Stores a list of fields that apply to the project.
Fields: pfid (primary), projid (ref project), fieldid (ref inputs)
One side note here. Make sure you take care not to let users store personally identifiable information into something like this. Or if you do, make sure you take the necessary precautions to safeguard that data, which is a bit different in this setup than in most cases.
I'll try to explain my problem and let´s see if I get some help.
I`m trying to design a DB. This data base will contain users and forms but my problem is how to design it to save forms.
The forms will be created by the administrator when he needs them, so in the DB I have a table to save the form name. Another table with all the possible fields for all the forms and another table where form-names and fields will be save so I can see all the field that a determinated form has.
An example: In FormName table I have 3 form names: Personal Info, Computer Knowledgement and hobbies. And in Fields table I have, for example, Name, Address, Phone, Operating Systems, Programming, Bike ridding, playing pc games.
I decide to create a form with name number 1 (Personal info) and fields number 1,2,3 (Name, Address, Phone). This information is recorded in another table called full-form where it´s saved form name id and field id. This is pretty clear for me (perhaps I´wrong).
The tricky part comes now. Some user decide to fill the personal info form so the name of the form and each field will has to displayed. When the user fill the form it has to be saved some way so the administrator can see the name of the form, each field that that form has, who filled the form and the information written in each field. And all this should be displayed not only in the DB but in some different way like a table, for example.
By the way... I´m using cakephp and mysql.
Thanks in advance,
Abraham
As far as I understand, setup looks like this. As you said, we have 3 tables:
'formname' = id, name (for form names)
'formfields' = id, fieldname, attributes (for form names, added attributes in case you need them)
'forms' = id, formname_id, formfields_id, formfields_order (ready forms and possibility to order field in form)
And also you should create additional table where to store submitted values
'forms_values' = id, forms_id, value (in this case one row for each field)
If you want to relate those values to specific user, one more table should be created
'users_forms' = forms_values_id, user_id
Of course there should be users table as well.
My suggestion is to drop table 'formnames' and put form name in 'forms' table.
Then table 'forms' will contain
id, form_name, formfields_id, formfields_order
Hope this answer will put you forward :)