All Questions
2,090 questions
32
votes
13
answers
26k
views
How can I disable a single checkbox in a 'checkboxes' FAPI element?
Title basically says it all, I want to disable a single checkbox of a checkboxes type FAPI element.
I don't want to do if with JavaScript, nor is changing it from checkboxes to multiple checkbox ...
0
votes
1
answer
809
views
How do I add the "onload" attribute to a script tag?
I need to add the onload event in jquery script tag as advagg does. I have done a bit of research, and I found that they are actually invoking hook_element_info_alter() and thereby add their ...
-2
votes
1
answer
1k
views
Serialization of 'Closure' is not allowed in serialize()
i am in the midst of fixing our website (which is built using Drupal version 7.67) that shows many errors after the PHP version is updated into PHP 8.0.
One of the errors that i am stuck now is this ...
8
votes
6
answers
16k
views
How to add extra arguments/parameters to ajax callback function?
I am using drupal 7. I need to add extra arguments to my ajax callback function. I have five fieldsets in my form, and in all of them same there are same elements, just their IDs are different. For ...
0
votes
1
answer
495
views
Delete confirmation as popup
I have a view containing saved user webform drafts set up in a table format. I have given permission to the authenticated user to delete own submissions. When clicking the delete link located on the ...
0
votes
1
answer
1k
views
How can I add an AJAX callback to a checkbox?
I am using taxonomy manager module I want to add ajax callback to checkbox tree view for checkbox is checked condition but it is not working can some one please suggest me. I have modified the code ...
41
votes
3
answers
61k
views
Adding CSS and JS to form with attachments
I need to add some external and local CSS and JavaScript files to a form, but I can't seem to find the right way to do this. Do I simply add the paths and URLs for the JS and CSS files?
I assume $...
0
votes
1
answer
104
views
Why does this code to create a dependent dropdown not work?
I am trying to implement the dependent dropdown option in Drupal 7 from this URL http://w3shaman.com/article/creating-ajax-dropdown-drupal-7. When changing the first dropdown value, it is showing the ...
0
votes
1
answer
838
views
Call #ajax when a checkbox is checked or unchecked
I have a Drupal 7 form that I want to be a single checkbox. When the checkbox is checked, I want to call an ajax request that hits an API to update the value, same for when I uncheck it. However, this ...
0
votes
1
answer
594
views
form #type => checkboxes with zero / empty option value
I am building something which uses a form element with '#type' => 'checkboxes'.
I want this to be reusable, so it should accept anything as option values that works as a PHP array key (integers ...
0
votes
1
answer
526
views
How can I modify the "Password policy constraints" text?
I'm looking for the easiest possible way to modify or alter the password policy constraints error text. The following is the default the users see.
The password does not include enough variation to ...
0
votes
1
answer
1k
views
How do I create an AJAX form with Add and Remove buttons for multi-value form element without submission button?
I would like to create a custom form with a textfield in which I input some data and it gets saved in the variable table.
The form should only contain the Add, Remove, and Add more button to add ...
25
votes
3
answers
15k
views
Multiple Values to Trigger #states
How can I have multiple values trigger the Form API's #states?
Say for example, I wanted this field to be visible not only if the value is 5 (currently works below), but wanted to make the field ...
15
votes
7
answers
20k
views
How can I know which button was clicked?
I have a form with a "Submit" and a "Cancel" buttons. In hook_submit(), how do I know which button was clicked?
4
votes
1
answer
4k
views
How to redirect a cancel button to destination on each form?
I'm using the following code to add a cancel button on every form I have for add / edit of every content type. The target should be the destination adress in the url
In some content types it is ...
35
votes
2
answers
63k
views
Custom validation for a form?
I need to add custom validation to a form, lets says add article form.
I was expecting something like hook_FORM_ID_validate() to handle this, but cannot find anything relavant in the API ...
0
votes
1
answer
1k
views
Populating select list from a taxonomy term field
I'm trying to populate a select list dynamically by pulling its values from a taxonomy term field linked to the current-user account. Just to clarify, below function is a hook defined by a module that ...
0
votes
2
answers
653
views
Submission handler for the user registration form doesn't work
I'm working on a Drupal 7 portal. I added a custom field to the registration form and I would like to get hold of custom field value when the registration form is submitted and before it is stored in ...
1
vote
1
answer
824
views
How to execute ajax action after image file upload with media widget?
I want to prepopulate some node fields with image metadata (using the EXIF module) right after an image is uploaded/inserted in a node image field with media browser widget and before the node is ...
7
votes
2
answers
4k
views
How to implement a multi step approval with webforms/entityforms based on form components?
Is it possible to invoke multi-step submission workflow using either Webform or Entityform? Here is the scenario of workflows:
An employee submits the form
Superviser gets notification,...
0
votes
1
answer
492
views
Add hidden field to checkbox and submit unchecked value
I want to submit a value if a checkbox is unchecked (on a node edit form).
Using theme_form_element I can add the hidden field as follows:
$variables['element']['#children'] = '$variables['element'][...
18
votes
3
answers
36k
views
How do I show a checkboxes form element that is selected by default?
How do I show a checkboxes form element that is selected by default?
I tried setting #default_value as in the following code, but it doesn't work.
$form['ios'] = array(
'#type' => 'checkboxes',
...
8
votes
4
answers
11k
views
How to create hook for altering every node form?
I tried:
mymodule_form_node_alter
mymodule_form_node_form_alter
and global hook:
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form['#id'] == 'node-form') {
#set ...
0
votes
1
answer
858
views
How to add AJAX call back from another AJAX result in a form
I want to use 2 AJAX call back within a form. The scenario is like I am having a text field and a Search button which is defined in the form alter function. After entering a text and clicking on the ...
17
votes
3
answers
26k
views
How do I alter the form submission handler?
For some reason I need to replace some characters (if exist) in every single textfields in any form just right before they stored in database. In other words I need a hook in which I could get all ...
0
votes
1
answer
3k
views
Captcha session reuse attack detected error message in form with anonymous user
I am experiencing a problem with the Captcha module 7.x-1.3 version (under Drupal 7.39)
I don't use webforms
My form is a simple Contact form
My form does not contain any AJAX field
My form does not ...
0
votes
3
answers
2k
views
How to set #default_value for radio button on Ajax Callback?
I've a form having a radios and 'select list with Ajax callback event'. When user changed selection from the select box, I tried to set the default_value for radio button. but it doesn't work.
In the ...
19
votes
3
answers
16k
views
Embed a "node add" form in a page
I'm looking for a way to embed a "node add" form on a landing page.
I was using Form Block, but it appears to bring many error because I was using a development snapshot version.
0
votes
1
answer
1k
views
Hook form alter to check date field is empty or not
I'm using hook_form_alter() to add some custom validations. I have to check if a date field is empty or not; when the field is empty, I need to display an error message.
I don't know how to get the ...
10
votes
5
answers
28k
views
How to avoid "An illegal choice has been detected" when updating select list values via ajax?
I have four entity reference fields to user entity in a form. Host form is node edit form.
Three of them are select lists, last is Inline Entity Form.
After adding a user entity via IEF I'm trying ...
41
votes
1
answer
6k
views
Why is hook_form_alter() so messy?
Here's an example I just ran into. I'm trying to put some HTML in the label of my field.
$form['field_feedback']['und']['#title'] <- has the title
$form['field_feedback']['und'][0]['#title'] <- ...
30
votes
5
answers
59k
views
Dynamic select list in the form (dependent dropdown)
I'm using Drupal seven. I want to make the options in a select list be dependent on the value chosen in another select list in a form. I'm sure this has been asked many times before, but I am having ...
0
votes
1
answer
483
views
How to pass theme variables in #theme in a form element?
I need to pass product variable defined in hook_theme() and invoked in #theme
but not sure how to pass product variables in #theme
Please suggest.
function storeinv_theme() {
return array(
...
2
votes
2
answers
3k
views
How to store data in database with Form API?
I'm new to developing Drupal 7 modules, and I can't figure out why my custom module's form data is not stored in my database's table called 'media_skins'.
I followed the info explained in Creating ...
0
votes
2
answers
1k
views
Boolean checkbox in sytems_settings_form
I have written the following code
$form['checking'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('checking',0),
'#title' => t('title'),
'#required' => ...
0
votes
1
answer
907
views
Trying to pass id to the ajax callback function, keeps overwriting, how to solve this?
I created a form which have a lot of images and a delete button on every each one of them. I used ajax to create a callback function which would delete the image. Here is part of my form:
foreach($...
2
votes
2
answers
1k
views
Iterate through all children of an element
I have a Drupal code below:
function myid_create_template($form, &$form_state){
$form['myid_templates_editor']['#access'] = TRUE;
foreach (element_children($form['...
0
votes
1
answer
548
views
How to validate a value against an existing field
I'm doing some custom stuff with programmatically saving fields with EMW:
$wrapper->my_field->set('my_value');
Problem is, this doesn't validate before trying to save the field. How can I ...
0
votes
1
answer
490
views
Warning: Invalid argument supplied for foreach() in form_select_options() (line 2837 of includes/form.inc)
I get the following erros on selecting the selectbox.
Here onchang of this field will populate another checkbox with city details id zipcode using ajax callback.
$zipcode_options = ...
1
vote
1
answer
883
views
Replace textfield value on ajax callback
1) Am i missing something here? it's not replacing the textfield value.
2) Also how do i replace if i have a multiple textfield and multiple button in a form.
<?php
function test($form, &...
0
votes
1
answer
626
views
Using 'return' with an ajax callback renders an entire page before my content is loaded
I'm developing a module that uses Openlayers maps and Drupal Commerce. When you click on the map, you should see products that relate to those coordinates of where you click. I have this working ...
1
vote
1
answer
2k
views
how to add checkbox value as json data
I have created a custom module for a form. And I have json data which I want to add as checkbox values.
$request = drupal_http_request($url);
$jsonarray =drupal_json_decode($request->data);
...
1
vote
2
answers
2k
views
Displaying the submitted values in a table
I created a custom form and after the form is submitted I need to display the submitted data in a table. This seems like a very simple problem. I am able to use dpm() and drupal_set_message() to ...
3
votes
3
answers
2k
views
Dynamically add input field using #ajax
As the question says, im not clear on how to go about adding new input fields depending on values of certain fields in the form.
I got as far as setting a callback and a wrapper, but i just can't ...
1
vote
2
answers
2k
views
Cannot Disable User Programmatically With user_cancel()
I want to disable user using user_cancel method.
//A function that disables a user.
function myid_admin_disable_user(){
try{
$edit = array(
'user_cancel_notify' => true,...
1
vote
1
answer
473
views
How to specify entity reference fields when programmatically submitting to user_register_form
You'd think this would be easy. I'm calling drupal_form_submit('user_register_form', $form_state)
to automatically register users after they have completed filling out a Webform.
But I have some ...
1
vote
2
answers
603
views
How can I make the coupon code field in commerce mandatory?
Using D7 commerce coupon/discount modules. I need to make the coupon field mandatory. Every order needs a coupon code entered.
There is no standard "required" checkbox on the field and I tried using ...
1
vote
2
answers
1k
views
Check if form already failed validation
I added a validation hook to a node creation form.
For my project, i need this validation only ONE time: basically i just check if a value already exists in the DB and i notify it to the user. If the ...
10
votes
7
answers
13k
views
Disable an option for the select form field
How do I disable an option in the select form field?
$form['feed'] = array(
'#type' => 'select',
'#title' => t('Display of XML feed items'),
'#options' => array(
'title' => t('...
7
votes
3
answers
21k
views
How do you theme a content type's create/edit form?
Like it says -- I've got a D7 content type whose editing form needs to be themed. I did this all the time in D6 by registering theme functions in template.php and writing the associated theming ...