The form API is a very strong, robust, easy and scalable API for creating forms in Drupal.

learn more… | top users | synonyms (1)

0
votes
0answers
9 views

Dynamic form building - cleanest way to substitute tags with form elements?

I have a string with tags, and form elements with elements corresponding to that tags: $line = "This module contains [quantity] items of type [type]." $elements = array( 'quantity' => array ( ...
0
votes
1answer
18 views

how to automatically retrieve selected value

is there a way to automatically retrieve selected value from dropdown or radio to form below? example in the image below, if i select radio button "randy", then the value "randy" automatically fill in ...
0
votes
2answers
28 views

Why is my Multi-Step form going back to the first page instead of moving to the third?

I've buit a multi-step (3 steps) form in form api, and going from step one to two works fine, but going from 2 to three just brings me back to step one. function multi_step_menu() { $items = ...
0
votes
0answers
7 views

Form API Ajax - how to disable also form elements that will be changed, not only triggering element?

So, element that triggered AJAX gets disabled. But how to make Drupal also disable everything inside ['#ajax']['wrapper']? After all, allowing user to edit something that will get replaced as soon as ...
0
votes
1answer
16 views

Form Default Values missing on theming form

Long story short when doing some basic theming on a drupal form the default / previously saved values refuse to display within the form fields (works without theming of course). In the code exerpt ...
0
votes
0answers
24 views

D7: Theming radios: None of the options passed to custom theme function

I'm trying to theme radios. To be exact, I want to make the return value of the radio button its label's class. My form looks like this: array( '#type' => 'radios', '#options' => ...
2
votes
1answer
44 views

What is the proper way to return the results of custom module's form submission?

After spending hours and hours online researching, I'm more confused than ever about something that seems like it should be a very straight-forward task - Using my module's custom form, How do I ...
0
votes
1answer
37 views

Setting value to checkboxes in a form

I've been having troubles with form_set_value(). I've extended the Search form, everything works, but after submission, the form values for those fields added by me return to default (see the code). ...
1
vote
1answer
14 views

How to add variables to Drupal.settings using form#attached?

I found this example: http://deeson-online.co.uk/labs/how-use-formattached-javascript-setting-drupal-7-form-api I tried: $form['#attached']['js'][] = array( 'data' => array( ...
1
vote
1answer
34 views

How to get forms to save variables to the correct place

I maintain a contrib module, and I'm in the process of porting it from Drupal 6 to Drupal 7. The module (http://www.drupal.org/project/csm) adds fields to the edit form for each content type (i.e., ...
1
vote
0answers
14 views

Using ajax to filter drupal autocomplete form

I'm trying to build a custom search form, and I want to limit the scope of the search with a dropdown select menu, ie. choose "jewelry" in the dropdown menu and the autocomplete form will only return ...
2
votes
1answer
23 views

How to fill form fields based on other fields values using AJAX

I have 3 fields. On blur on any of them I want to look for empty ones - if blurred one has value and any of the others does not, I want to copy value. Obtaining value is easy, simply ...
1
vote
1answer
27 views

What is the best way to pass values from one form to another with fapi?

I have one form that is just an options input. When I select a value then go to the next page there is another form that I want to have three hidden values based upon the chose value of the first ...
1
vote
1answer
44 views

form ajax forget's changes made in previous ajax callback calls

Why do changes don't get saved in $form, or what is it that's overriding it? I would like to set custom class to multiple fieldsets in an ajax callback function: if (something) { ...
1
vote
1answer
34 views

How to put links into description text?

In my field's description, I want to link to more documentation. If I do it like this: $form['field_name'] = array ( '#description' => t('Here are some words about') . ' <a ...
0
votes
0answers
19 views

form ajax how to change multiple elements [duplicate]

How can i change multiple form elements in ajax callback and get this changes in future ajax callbacks? i would like to set custom class to multiple fieldset's in ajax callback function: if ...
2
votes
2answers
29 views

Adding options to Drupal search

I've been working on a site and I need to change the search. I've changed the search form with hook_form_alter(), added some checkboxes, ... Now I need to get the new data to the ...
2
votes
1answer
37 views

How to hide empty fieldset, but leave prefix and suffix in place?

Simple as this - I have a Form API fieldset with dynamically changing content. When it's empty, I don't want to show it at all. I use #prefix and #suffix to generate div my AJAX works with. When I ...
0
votes
1answer
26 views

Run a boolean test function on form submit

Is there a way to run a function when a user submits a form in Drupal that returns a true or false. If it is true, run the submission handler. If false, return an error. Application: I am using ...
1
vote
1answer
26 views

How to remove form elements before submitting the form?

All form items in Drupal must be created with Form API, otherwise form values in $form_state and in $_POST variables are empty after submitting the form. But sometimes I need to have in form some ...
-1
votes
0answers
19 views

How to redirect to a specific admin page and alter the form there? [closed]

I custom create users. I want on each user creation to check specific option found on administration side on a form provided by another module. (e.g. it allows user to receive notifications by ...
1
vote
1answer
25 views

How to nest form into another form?

I have 2 modules. Let's call them Publisher and Publication for discussion's sake. Publication module requires Publisher module. Publisher module provides form to edit publisher's data. Publication ...
0
votes
1answer
19 views

How to stop text-boxes in my custom block trailing past the block?

I am creating a module with a custom block. Even through googling, I still could not find an answer to my question "how do you theme the elements in a form?" I think it is the fact that I don't ...
0
votes
0answers
43 views

how to get radio value from radio button by form api drupal

How to get radio value from radio button by using the following code $form['pd']= array( '#type' => 'radio', '#title' => t('Programme Day'), '#options' => array(0 => 'One Day ...
0
votes
0answers
26 views

Changing a form value or input field value during the submit handler

I am trying to change the value of a text area field at the end of my submit handler. I have tried using form_set_value and $form['form_id']['#value'] = 'something'; to accomplish this but after ...
3
votes
1answer
34 views

add user to role

i'm trying to create custom drupal 7 module , i'm using 'user_roles()' function to get all the roles in the system , and then i assign those roles to checkboxes API Form Control ...
0
votes
1answer
28 views

webform save draft after each field update - ajax error for anonymous user

I wanted to save webform's draft after each field's update, and i did it with help of this post: Webform save draft after each field update . But it is only working for logged in user, if i try it ...
0
votes
0answers
10 views

form alter and module load include

I have module that I alter a form using hook_form_alter. In this alter, I add a submit function to the form that is defined in a include file that I included in the hook_form_alter implementation ...
5
votes
2answers
117 views

How to cache forms with a reverse proxy and deal with stale form tokens?

When Form API generates a form, it also generates a token that is passed out with the form in a hidden field, and expected to be returned back. If it is, the form is processed. If a rendered form ...
0
votes
1answer
46 views

Attach #ajax to submit button created in hook_form_alter with #markup

I created a custom submit button for the user-login form using #markup because I couldn't alter submit button html to resemble what I needed. The second custom submit button with the needed html is ...
2
votes
1answer
44 views

Best practices for protecting from injection on form fields

I am building a form in Drupal 7. I have a textarea field and would like to know if it is safe to get the field content ($form['values']['field_name']) and save it to the database using something like ...
0
votes
0answers
16 views

Core form api autocomplete to include categories?

I have added autocomplete to a form field using the core section of the form api see here This all works fine but I cannot find any example of how to incorporate categories into the autocomplete ...
0
votes
1answer
47 views

How to insert html inside form element div

I want to enhance the login form fields with icons from Font Awesome. For this I need to add some html inside the div of the name and pass fields (to be able to position accurately with css). The html ...
3
votes
2answers
82 views

How to write custom Form API elements for Drupal 7?

In context of this question I wanted to ask - how to provide custom controls to use with Form API? Especially ones that needs to be exploded into javascript and at least one additional hidden field to ...
3
votes
0answers
47 views

How to add tri-state checkboxes to form created with Form API?

I want classical tr-state checkboxes, like the ones on the picture below: Checked would mean "true for node and all it's children", intermediate "true for some children, leave it as it was" and ...
1
vote
2answers
45 views

Adding #ajax to checkboxes and getting selected values in callback

I've been trying to use #ajax callbacks on a form. I've got this working with radio buttons, so when I've debugged the form I get the value associated with the radio button as '#value' under ...
0
votes
0answers
18 views

Altering form state based on ajax generated field value

I have a form generated with the the D7 api that includes an ajax generated radio group. I would like to alter the state of another form element based on the value of the generated group but it is not ...
-1
votes
0answers
23 views

Problems with hiding form elements with the #state attribute

I don't have a problem implementing this (I have used it several times successfully). However, for some reason the form fields that are meant to be hidden are visible. Does the state attribute depend ...
0
votes
3answers
32 views

How to assign IDs to each radio button in drupal form radios?

I am using drupal form radios, I can use Prefix and Suffix to assign IDs to group, how can I assign different IDs to each radio button inside the radios element? Thanks
0
votes
0answers
17 views

Custom Creditfield in Drupal Commerce Checkout

I'm trying to set up a Drupal Commerce website. And since PayPal really made a mess of his latest API's, I want to add my own fields where users can provide a creditcard number and cvv code. So I ...
1
vote
1answer
41 views

Are there any disadvantages in placing form elements in custom containers?

I've got a form layout in which form elements are separated between 2 divs: one with float: left, the other with float: right. I have to keep it that way. Is it fine to place form elements in ...
1
vote
1answer
25 views

determine value differences between form submissions

I have an entity form that user can submit multiple times. What i would like to do is during validation get current values in the database and compare with the once that user just entered. I'm using ...
0
votes
1answer
50 views

Is there a callback for the managed_file form element, called on succesful upload?

Is there a Javascript/PHP callback for the managed_file form element that is invoked when the file is successfully uploaded? (I mean when the "Upload" button is clicked, not when the form is ...
-1
votes
0answers
30 views

system_settings_form file upload handling

is it possible to upload many files - images - with system_settings_form and save them to database? My configuration require files upload but can't find good examples of uploading and details about ...
0
votes
0answers
21 views

Add text box on

I'm trying to use AJAX to create another text box in a fieldgroup. I got it to work if I have a button, with a combination of 'submit' and ajax callback parameters. I'm trying to combine those two ...
0
votes
1answer
54 views

“Add More” button to form

I'm trying to add an "add more" field to a form in my custom module. I've been looking at the examples module, with no luck. Here's what I have so far: $form['#tree'] = TRUE; ...
2
votes
1answer
60 views

How to omit form's validation at AJAX button click?

I have an AJAX button that should update form fields according to data already provided by user: 'ajax_button' => array( '#type' => 'button', '#value' => t("Scan for tags"), ...
6
votes
2answers
97 views

How do you change the location of `form_set_error` output?

Is there a way in Drupal 7 to change the location of the output of form_set_error? At the moment, it calls drupal_set_message which queues all the form's errors to the top of the screen. What I ...
0
votes
1answer
53 views

Setting a Drupal.settings JS variable from a form field

i'm working on my first custom module and really fumbling along :). thanks in advance for your advice! goal i've added a checkbox to the comment form. if the user leaves it checked, then following ...
1
vote
1answer
49 views

How to NOT turn element read only when waiting for '#ajax' callback in Drupal 7 forms?

I need a simple '#type' => 'textfield' field. When a user types in it, I want to update another section of my form. Just a more elaborate version of built-in autocomplete field, really. So I added: ...

1 2 3 4 5 22