I'm new to Drupal, but not new to PHP/MySQL/etc...
Problem:
I have several forms that are completed by the user when performing various actions (upload, edit, create, etc). One of the fields contains project information that needs to be input in a specific manner. To prevent human error, I'd like the field to be presented as a guided input. I could create each of the required fields on every type of form, but it seems more efficient to create one dynamic field and reference it on other forms. Is there a straightforward method of accomplishing this? Would creating a custom field type that stores array-based values achieve this?
Desired outcome:
A modular way to add a field into applicable forms that guides user input.
I ended up solving this by creating a custom field using hook_field_widget_info() and hook_field_widget_view() to make a textarea. The guided input is returned to the textarea with JS as a JSON string (this is the field that stores in the database). The JSON string is processed in JS for display in the formatter.
Related
Im writing simple forms generator where user can add various types of fields.
For example (text,text,email,file,checkbox).
Then i put data about those inputs to DB ( name, placeholder, default value etc).
How to generate symfony form without knowing what types of inputs and amount will it have?
Thanks for your help
What I want to do
I'm trying to build a form in Symfony 2.8 that requests the user's choice between many types of credentials and add an input box to the form it's similar to this one but I use a select option field instead of buttons.
What I did
I was able to create this form with HTML and JavaScript.The user can select more than one credential type only once except the OTV Option that can be selected without limits.
image here
What's my problem
I need a way to store user's data in a session and get them in my controller.
Is it possible to pass submitted data from HTML form to a Symfony controller and if not how can I build a similar form with Symfony's formBuilder ?
CollectionType is probably what you are looking for.
For your purposes, you can think of it as adding rows to the end of a two-column list. The Left Column has credential_type with Name, Email etc in a <select>; and the Right Column allows for your text values.
You'll have two FormTypes: one for the list, and another for the list item. In the list item FormType, you should be able to set a CallbackConstraint to validate e.g. that email values are valid upon form submission.
All user changes are saved at the same time, only when the form as valid.
I think you can do that. There is CollectionType in Symfony form. You can read about it here and how to implement it here
P.S. The main problem in this case is to generate specific names for dynamically created fields to provide a normal handling data in controller.
As I am writing my program by PHP programming language and Mysql DB in WordPress CMS, I built a plugin to create and handle a customize form in a special workflow to the needs of our customer.
After form being filled by the user, one of the editor users of the site would check the data of the filled form and validate them.
The screen shot of the validation page that is show to the editor users is like this.
As you see I fetch data of the form from Data Base and print them to the editor users to validate them. At first all the field are display in green background. By using jQuery I give the editor users the ability to click on the filled that has problem and change the color of the field to red. like the below screen shot.
My question is, how could I store the data about which fields are filled with wrong data (The field that are showing with red background) and use this kind of meta data to create an edit page for end user to correct that fields?
Of curse there are a lot of way to do that. The easiest but in my idea not optimize way is to add Boolean fields match to the form fields in Data Base and submitting hidden field according to that Boolean fields to store the information that each field is correct(TRUE) or not correct(FALSE).
The forms that I am working on have about 174 field that most of them are varchar(254). So the size of data that is storing in data base is huge and I don't wanna make it larger.
Ultimately could you please help me. Is there any other way to store the jQuery actions of the editor users and show that stored data to end users.
I am looking for your help.
Bests.
I'm using Zend Framework and I currently have an existing form using zend-form which functions as required.
I want to add another optional text field to it, but allow the user to choose to display the field and also display it multiple times. e.g. A user registration form with an 'alternative emails' area, allowing the user to add further text fields for each of their email addresses.
Unfortunately, I'm not sure how to go about this. I think sub-forms might be the way forward, but not too sure.
Ideally, once the form is submitted I'd want the data in an array so that I can process it for storing in a MySQL table afterwards.
See this excellent post by Jeremy Kendall on dynamically adding fields to a form:
Dynamically Adding Elements to Zend_Form
Upshot is to use jQuery on the client-side to add fields and maintain a registry of the new fields. Then on the server-side, call a new preValidate() method on the form object which checks the posted registry and adds the required fields into the $form object before standard processing - like isValid() and getValues() - is invoked.
Why don't you make an AJAX call to an addfieldAction() method in which you generate the HTML of another textfield and return that? You can still make use of Zend Form and the whole form can be processed the normal way.
Using CakePHP 1.3, I have a (working) form that has dynamically created form fields (via Javascript). Everything works great, multiple models are saved via saveAll(), and it's just beautiful.
But, I get black-holed to a 404 whenever I enable the Security component (hoping to get some of the auto-magic CSRF protection).
I understand that this may be (probably is!) caused by the dynamically created form fields, as mentioned in the docs.
Is there a way to get them to play nicely together?
You can't have your Cake and eat it, too. (Cha-ching!)
CSRF protection means precisely that only a certain list of form fields is allowed to be submitted. This list is decided upon and fixed at the time the form is created. You can't be CSRF protected and dynamically alter the fields in the form.
There are two solutions:
If the number and names of the dynamically created fields are limited, create them all in the form and hide them using CSS, then show them using Javascript. This way you're not dynamically creating the fields, but are only dynamically showing them.
If that doesn't work, you can either whitelist the fields using the $disabledFields option (again, only if their names are known in advance) or disable CSRF altogether with the $validatePost option.