Questions tagged [forms]

Use it for questions about the Form API. Don't use it for entity or entity field forms.

Filter by
Sorted by
Tagged with
3
votes
2answers
424 views

How can I programatically add the default AJAX throbber to a form submit?

I'm trying to add the AJAX throbber in core to a form submit button, specifically the Private Message module new message page. Here is my code: function MYMODULE_form_privatemsg_new_alter(&$form,...
0
votes
1answer
29 views

How can I set value to hidden field (Form Api) and send them with post method?

I’ve created a form with Form Api in a custom module. I send datas with post method to a web service. In buildForm() $form['mode'] = array( '#type' => 'hidden', '#value' => '...
0
votes
1answer
396 views

How can I remove “please wait…” from a form?

I saw this Remove the "Please wait" text on Ajax Call but I can't find the form element. <?php dsm($form);?> and <?php dpm($form);?> return errors. This is what I found in $node: ...
0
votes
1answer
417 views

How to disable Rich Text Editor in image field caption ?

I am using Image Field Caption module. It provide a image caption field but I don't want any rich text editor appearing for the caption field. How to disable that for any specific field?
1
vote
2answers
704 views

How can I stop auto uploading of managed_file elements?

I am trying to create a field to upload the xml format of site map. But when I add a file to my filed it automatically uploaded and saved in the S3 bucket before I click on the submit button. The ...
2
votes
1answer
383 views

Drupal 7 Form - static field works, dynamically modified element gets lost

I'm new to Drupal forms - trying to figure out a maddening problem. I have a content type of 'doc-upload' with various fields including 'publisher_code'. When I define the 'publisher_code' field ...
0
votes
1answer
4k views

What is incorrect with this HOOK_node_presave method ?? Trying to modify a FAPI textfield

/* * Implements hook_node_presave() */ function custom_kca_node_presave($node) { drupal_set_message('DEBUG: PRESAVE Called'); if ($node->type === 'product') { $node->...
0
votes
1answer
336 views

How to drupal autocomplete result link to node page?

In my drupal 7 site I create a custom search form with autocomplete text field which is showing node title.I want this node title link to there node page. For this I write this in my custom module ...
0
votes
1answer
254 views

Generating Ubercart orders programmatically

I am trying to generate ubercart orders programmatically in Drupal 8 and am doing it this way: $order = Order::create(array( 'uid' => $uid, 'order_status' => uc_order_state_default('...
0
votes
2answers
50 views

altering the add content type form

I am going to alter the form of add content type form and for that I used the hook_form_FORM_ID_alter() Here is my code which implement in the module file, but it is not working. function ...
0
votes
0answers
45 views

Set Custom Form Element Value in Extended LinkWidget Class

I have a class extending LinkWidget and would like to add a new form element. I have omitted all code except what I have added: class CustomWidget extends LinkWidget { public static function ...
0
votes
0answers
50 views

Attached User profile form gets error on save

I had attached my user_profile_form in my custom form and called the custom form by the defining a new path in hook_menu(). The user_profile_form got rendered correctly. But while saving the form I'm ...
1
vote
1answer
662 views

States visibility in type select and radio in drupal 7

I have a custom form $form['basic']['legal_form'] = array( '#type' => 'select', '#options' => array( 'option1' => 'option1', 'option2' => 'option2', 'option3' => '...
2
votes
1answer
895 views

form_set_error checkbox CCK 2 drupal 6

How can I highlight the checkbox boxes when be validated a CCK field? (CCK 2.9). Data is validated correctly, and message is displayed correctly in the head of the form, but the checkboxes does not ...
1
vote
1answer
289 views

Form API Ajax trigger callback with size of input

I use the API Form of Drupal 8 to create my form. I had an ajax callback on a field: $form['association']['numero'] = array( '#type' => 'textfield', '#title' => t('foo'), ...
0
votes
1answer
18 views

How to set “Language Selector dropdown” required in node form

I want to know How to set "Language Selector Drop-Down " required in node form? I tried to do this via hook_form_alter, but it seems $form['language'] is not created in this hook ! Is there any hook ...
-3
votes
1answer
1k views

Form data get converted into uppercase at the time of saving [closed]

I have big drupal form and when the form get save, at that time I need all form data should be converted into upper case and then should get save.
0
votes
1answer
673 views

How do I correctly load user_profile_form() to use in my theme?

I am trying to theme the user profile edit page using user_profile_form() and need help how to achieve this. In my template.php I have the following code: function marinelli_theme($existing, $type, $...
0
votes
1answer
51 views

Custom Save and Unpublished button for node

While clicking Save as draft button, it will save the node but while it have to redirect to the created node it gives error The website encountered an unexpected error. Please try again later. and $...
0
votes
1answer
554 views

How can I save a file in specific folder?

I want to upload files to specific folders. How can I achieve this programatically. How can I modify below code such that upload_location should be dynamic. $form['document'] = array( '#type' ...
1
vote
1answer
405 views

Why the action buttons are not working?

I am rendering the user profile edit form ($form_id = 'user_profile_form') on a custom tpl.php page. All the custom fields are user-defined under configuration > Account Settings > Manage Fields:...
0
votes
1answer
361 views

Validate a file extension using getMimeType

I want to create a hook that will validate a file upload and only allow jpg extension or a multiple array jpg, gif. I am not sure how to do this. If this below can validate the length of the file ...
1
vote
0answers
21 views

Any security issues accessing $_POST and returning values from it in AJAX commands?

Just wondering if there needs to be any sanitization here: /** * Implements hook_ajax_render_alter(). */ function my_module_ajax_render_alter(&$commands) { if (isset($_POST['...
0
votes
0answers
406 views

Entity form calculator in Drupal

I was wondering, is there anything like webform calculator for entity forms?
4
votes
2answers
2k views

Get file name upload via form api?

I made a module to upload file in form, below is my code snippet, I am able to save file in proper folder but I want to get name of file uploaded so I can save it in database and make reference for it,...
0
votes
1answer
625 views

Load Javascript when a particular form is loaded

I have the code below in my own drupal module(myid): myid.module file: function myid_init() { drupal_add_js(drupal_get_path("module", "myid") . "/js/myid.js"); } function myid_menu() { $...
1
vote
1answer
58 views

How to alter a custom form

I am using Drupal 7 to create an registration form, there are: username, email dan password fields, but I want to make an username checking while user leave username field (ajax). I found an module as ...
0
votes
1answer
223 views

Redirect to referrer, confirm_form

I have few confirm_forms which could be invoked from different places. I would like to redirect user to proper place after cancelation. Referrer Header is not good way to do it so I'm looking for good ...
0
votes
1answer
426 views

Create a simpletest test to add additional form elements using the “Add another item” button

I am trying to create a test case for my custom module using simpletest in Drupal7. I want to create a node. The problem is that the node edit form contains a number of fields which can have ...
0
votes
1answer
1k views

Ajax callback works only once

I am using Drupal 7. I want to rebuild a part of form when a button is clicked. My form looks like this: $form['me'] = array( '#type' => 'fieldset', '#value' => t('name'), '#prefix' ...
0
votes
1answer
401 views

How to store second dropdown value in database

function YOUR_FUNCTION_THAT_DISPLAYS_FORM(&$form, &$form_state) { $query_state=db_select('state', 's'); $query_state->fields('s',array('State_code','State_name')); $query_state->...
1
vote
2answers
533 views

Multi step form

I am using Webform module, Can anyone help me to make a multistep form where suppose on front page i choose select service and select location and on submit a new form opens in pop up. Pls suggest ...
1
vote
2answers
594 views

How to set Form API link href to # hashtag

In Form API when creating a link, the output a-anchor will have a prefix of "en/" in front of whatever I set as the href value and if href is set to "#" it will be output with the language prefix and #...
1
vote
1answer
533 views

Inline entity form ajax

I am trying to update some field options in an inline entity form with ajax. This should happen, when someone selects a value in an other field. I already have some code which "works", but the ...
6
votes
3answers
7k 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
0answers
34 views

How to get identifier for menu link item in form hook?

How to get something unique (like 'menu link id' mlid in Drupal 7) in the form for editing one menu link item? hook_form_alter(&$form, FormStateInterface &$form_state, $form_id) { $mlid=... ...
0
votes
1answer
12 views

Hooking into page specific instance of checkout flow form

I'm working on manipulating the buttons used for the checkout flow of using D8 Commerce 2. I'm using MYMODULE_form_commerce_checkout_flow_multistep_default_alter but its changing both the form buttons ...
0
votes
1answer
308 views

Whats the best way to add an object to a form array? [closed]

What is the best way to add an object to a form array so that any form_alter hook can interrogate the form for the object and act accordingly. For example, I have an object I pass to my form which ...
1
vote
1answer
402 views

Clean url for custom query parameters

I have a custom filter form in my site and the form submitted by the filters adds 2 Get variables to the url. However, the variables appear in the form of: http://example.com/newpage?param1=a%2Cb&...
0
votes
0answers
16 views

$form_state->setError on autocomplete field

I have a form with custom validation and an autocomplete field. I have no problem to set errors for text fields, for example for a List (text) field I can say $fss = $form_state->getValue('...
0
votes
1answer
59 views

how to extend FormBuilder::processForm from multiple API endpoints in one class

I'm trying to consolidate my form processing by entity_type, without rebuilding the forms (just using the default forms provided by Drupal. I have dynamic routes pointing to a _controller::method. I'...
-1
votes
2answers
104 views

How to make file description field as required?

I would like to set the file description as required. I tried it with this code: function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form_id ...
0
votes
1answer
410 views

hook_form_alter #attributes and #disabled

I'm using Drupal 7 and Advanced forum. The users when will create a new topic will be able to select the forum container and forums, but if they select a container, an error will be showed. I want ...
0
votes
1answer
35 views

Programmatically change the weight of a form element

I have a user activation/registration form with different attribute like Captcha and security questions which are coming from different modules. I want to change the display order of form elements. ...
0
votes
2answers
641 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
1answer
37 views

Adding #ajax callbacks to form elements in HOOK_form_alter()

I'm trying to add an #ajax callback to a select element on a form that is created in another module on a Drupal 8.x site. When I add the #ajax callback using HOOK_form_alter() in my module, the Ajax ...
0
votes
0answers
15 views

How do I programmatically get the value of a Markup module field when validating the form

I'm not able to access the content via traditional methods like: $form_state->getValue('field_canvas_markup') The field doesn't appear next to other fields in Kint. Here is the code I have right ...
1
vote
1answer
75 views

Use an Address Field with 3 lines for the street [closed]

I'm working on an Entity where I created a field containing Address informations (like country, city and street). The default Address Type in Drupal 8 supports only 2 lines for the street information....
0
votes
1answer
20 views

How to change the value of the Submit button text when extending ConfigFormBase

I need to change the value of the Submit button text when extending ConfigFormBase. What is the correct way to do it?
1
vote
2answers
483 views

Setting the default value of an entity form radio button using hook_form_FORMID_alter

I have written a custom Drupal 7 module which needs to set the value of a radio button of an entityform based on a value queried from the database. I have tested hook and it is working as i am able to ...