We’re rewarding the question askers & reputations are being recalculated! Read more.

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
1k views

What is the twig template name for a node edit form?

In Drupal 8, what is the twig template name for a node edit form for a custom content type called for example "device". For a default node we use node-edit-form.html.twig So what is the edit ...
0
votes
1answer
29 views

Menu options missing in node form

In Drupal 8, despite the fact that there is a menu set for the content type, menu options are not showing in the node form. I have disabled some menu modules in case they were interfering, but with ...
0
votes
1answer
488 views

Ctools content type not responding to form api ajax callback

I am using a ctools content type plugins to render a custom form that will have only one submit button. The submitbutton will switch an eck entity field (boolean) from 0 to 1 and back (if pressed ...
0
votes
1answer
52 views

ContentEntityForm buildForm method parent out of memory

I have the following issue with my form class that extends the ContentEntityForm class. When calling the parent buildForm which is needed my system runs out of memory. /** * {@inheritdoc} *...
0
votes
1answer
40 views

Display the results of a form submit on the same page just under the form

I have created a form and it takes in 3 values which are Brand, Item and Zipcode. The values are queried and the results are fetched the database table. I want the results to be shown in a table ...
2
votes
1answer
418 views

Create form for image selection from the content

I have a content type with title and image field in it. Now, I want to show a form to the user which will show the image thumbnail, title and a checkbox below each image with the value of respective ...
2
votes
1answer
516 views

Can I add text to a form file upload field?

Is it possible to add text/markup to a file upload field similar to the image below? I thought that something like $form['actions']['edit-field-upload']['#prefix'] = 'First'; in a hook_form_alter ...
0
votes
0answers
32 views

How to add Conditional Fields in Paragraphs

I was able to add Conditional Fields in Paragraphs using this article https://agaric.coop/blog/conditional-fields-paragraphs-using-javascript-states-api-drupal-8#comment-209 But it controls and hides ...
0
votes
2answers
485 views

How to get selected Value in the listbox by using form api

I have created a form with fields titled State and City. After selecting the state's appropriate city records, they will be loaded into city listbox. Until now they were working fine, but after ...
0
votes
2answers
42 views

How to find the pressed button

Help me please. How can I get the value of the pressed button. Thanks! $items = []; foreach ($result as &$value) { $items[] = [ $form['repo'] = [ '#type' => 'fieldset', '#...
1
vote
2answers
1k views

Set the width of the select box in Drupal form

Currently I have a select box in a form as follows : $form['fieldset']['event_trigger'] = array('#type' => 'select', '#title' => t('E-mail event trigger'), //'#default_value' => $...
1
vote
0answers
65 views

Ajax field sometimes loses value on form submit

I have a Drupal 8 form with several fields that update a price via Ajax. One of the fields is failing to a textbox, that does a callback on the blur event. It looks like this: $form['free_amount'] = ...
0
votes
1answer
56 views

Allowing anonymous user based on condition

I'm currently working on a custom module with an access form and set permissions for anonymous users. I'm trying to make it so that when an anonymous user enters the password in the access form, they ...
5
votes
3answers
4k views

How to get triggering_element

I want to get triggering_element element on form_alter after form rebuild, Also I know that this could be used on submit handler on Ajax controller to findout which element cause form submit or Ajax ...
0
votes
1answer
133 views

Render comment edit form in block

I am using following code to render node comment form in a block: $comment_form = drupal_get_form('comment_node_<node_type>_form', (object) array('nid' => $nid)); print drupal_render($...
3
votes
2answers
7k views

How do I add classes to form elements in the theme layer?

I want to do it in template.php. The form ID is page_node_form, and there are six form text fields. The default class is "form-text." I want to add "text1," "text2," etc after "form-text" to each ...
-1
votes
0answers
10 views

Updating data in a form (set arguments from form)

Help me please. I would like set two arguments to ServiceGit.php from my Form.php and then get this again in my form. My app work so: I have $target & $target_id in ServiceGit. To default both ...
0
votes
1answer
555 views

Ajax form an multi-select

I have a form which provides select2 when the select1 is changed. However I would like select2 to be a multi-select. I can't seem to get this to work. It populates a single select input just fine, but ...
6
votes
3answers
15k views

Custom text/html in custom form module

I am following this tutorial and I've already created my custom form as Drupal 8 module. I wonder, how to add custom text/html in form? I mean when somebody goes to the path pointed in *.routing.yml, ...
0
votes
0answers
6 views

Form still submitted after form_set_error() is invoked [duplicate]

I've a case which is driving me nuts. Form is still submitted after form_set_error() is invoked for an element. I have in form alter function custom element_validation $form['field_test']['#...
1
vote
1answer
499 views

Set select list option value

I'm trying to set value of select list programmatically with hook form alter I have select list with options: $options = array(125 => 'USA'); and setting value like this $form['...
0
votes
1answer
453 views

Alter Registration Form Text

I am trying to alter the email description text on my user registration page. I have added the following to the bottom of my template.php file but nothing is happening. It seems like the function isn'...
2
votes
2answers
2k views

Is this the proper way to add a 'class' attribute to a form date element

$form['stop_date'] = array( '#type' => 'date', '#title' => t('Stop Date'), '#default_value' => date("Y-m-d"), // default to today '#id' => 'stop_date', '#attributes' => ...
1
vote
1answer
489 views

How do i generate token for each user they submit my custom form?

I have a created a custom module with simple form with only three fields ( Url, title & email ) , where user has to enter all the fields for submission. I am able to send the mail to the user ...
0
votes
0answers
32 views

Tableselect with return new response doesn't work

I'm newbie in drupal and I want to create contact list with dynamic search on ajax. I want to ajax load my tableselect. So I use return new Response(render($form)); where the form is tableselect. I ...
0
votes
1answer
511 views

Programatically Submitted Form With 'file' Field Throws Notice

This seems to actually be a problem in Drupal itself. In /modules/file/file.field.inc the function file_field_widget_form has a line like this near the bottom (just before the return statement): $...
0
votes
1answer
514 views

Is it possible to change the form submit handler from within a validate handler (need to redirect to another form depending on values entered)

I have an initial webform (based on 3.x of webform module/Drupal 7) that needs to redirect to a second form if yes is specified in a yes/no choice. Otherwise if No, the first form should submit ...
2
votes
1answer
41 views

How can I add a custom CSS class to checkboxes labels?

I'm using Drupal 8 with the Form API and the AJAX API, now I want to add a custom CSS class to every checkbox label, because I need to use the bootstrap custom checkboxes. PHP (slimmed): $form['...
0
votes
1answer
537 views

Update theme table using callback function in Ajax

I have two elements in my form: a select and a table element. Everytime onchange event is triggered on select element, I want to update the values in my table. I want to do query and change the values ...
1
vote
1answer
14 views

How can I get the checked attribute into Better Exposed Filters input type radios?

i'm having a BEF exposed filter representing a taxonomy, they're radios. It works well, but when i select a radio, it won't get in its HTML tag the property «checked». I guess the selected value of ...
0
votes
1answer
21 views

Redirect to view display after form submission

I'm using a form_alter hook to add a custom submit callback. I want to redirect the user to a particular page display of a view. However, I'm having trouble figuring out how to specify the path. In ...
0
votes
1answer
482 views

How to display the input box next to the label in a form?

My objective is to improve the look and feel of a form developed in Drupal 7. By default, I have (as an example): Name (label) BLANK INPUT box (below the label) How to display the label and input ...
-1
votes
0answers
11 views

submit button does not respond after creating custom theme in drupal 6

I am trying to implement a custom theme. However, after creating custom theme my submit function stop inserting data into the database. Any suggestions would be appreciated. hook theme-sdbpireq....
5
votes
4answers
2k views

How do I find a Form_ID for hook_form_FORM_ID_alter?

I want to alter the form for a content type I created for videos. The type is called Videos. How would I use hook_form_alter to alter the form to create the content?
1
vote
0answers
16 views

How to achieve dependent filters programmatically for views exposed form?

I have a requirement like Category and Sub-category should display as dependent filters. When I choose a Category next related sub-categories should show up in another field. These mapping is done in ...
0
votes
1answer
20 views

Drupal 8 - Add custom HTML with script to embed on a page as block

I need to add a custom form that has scripts and styles into a page as a block. Its dynamic, so I couldn't attach the scripts (#attached) as libraries. I just need to place the contents as is. $...
0
votes
1answer
713 views

Table Pager Rendered in an Ajax Callback Shows White Page

I have the callback function below that renders a table with a pager. Every page of the table is 20 rows. Below is the code: function myid_print_all_submitted_id_callback($form, &$form_state){ ...
0
votes
0answers
21 views

How to redirect a module button to a specific external Url [duplicate]

I'm trying to make a button type to redirect in an external Url and I don't know how to make it. I already make the simple Form and I need help for make this function. I'm using Drupal 8 Thanks in ...
1
vote
2answers
94 views

How can I display a message when “add another item” on an Inline Entity Form Multiple field is clicked?

In Drupal 8 inline entity form is there a "form_alter" or "submit handler" or some type of ajax callback for when a user clicks "add another item"? What I would like to do is display a message to the ...
0
votes
1answer
23 views

How to alter the search api views exposed form field value?

I have a search api view. Which has an exposed some exposed filters. The exposed filters contains postal code, city and latlong field. The user will enter the city and postal code and then in the ...
1
vote
1answer
472 views

How to update one select element via Ajax when using node_add

I have just created a new content type called pieza_musical. What I just want to do is update one select element via Ajax depending on another select choice, a dependant select. I'm altering the ...
0
votes
1answer
343 views

file_field_widget_form error when programatically creating nodes

I have a simple routine which I use to create nodes. The logic is something like this: function make_node($node_type, $field_data) { foreach ($field_data as $k => $detail) { $field_key ...
1
vote
1answer
461 views

Form is not being rendered in template file

I have tried drupal_render,drupal_get_form etc for rendering the form,but the form is not being rendered. Is there any error in code or else what else should i add to the code so that it works. ...
-1
votes
1answer
34 views

entity_autocomplete, multiple users

I would like a form element able to select multiple users. $form['forward_users'] = array( '#type' => 'entity_autocomplete', '#title' => t('Forward to these users (if multiple, select and ...
3
votes
1answer
443 views

Custom form values in hook_form_alter not available in custom validate function Drupal 7

I'm modyfing a node form to add a few extra fields. On submit, I need to program some extra logic to these values then save them to the node object. function module_form_alter(&$form, &$...
0
votes
1answer
499 views

Redirect to custom error page if node submit fails validation

I've embedded a node/add form on my homepage for submissions but for caching purposes, I need to have any server-side validation occur on a different page instead of itself. I.e. If the form fails ...
2
votes
1answer
1k views

Alter views exposed form drupal 8 [closed]

I have a view that in that view I set up 3 exposed filter, all working fine. I need to set a condition to show the third filter option to a specific user, it can be checked according to the user role,...
3
votes
0answers
27 views

Can I access more information (user inputs) using delta index?

I am working on an edit form of a content type, which contains several related inline_entity_form, let's say ief1 and ief2. When I fill and submit ief1 and come to ief2, I need to access the input on ...
2
votes
2answers
411 views

How to show label instead of value in custom autocomplete drupal 8?

I was making a custom autocomplete field and it worked as in when I type 'a' it shows me all the list of fruits with letter 'a'. But when I click on any of the options. I see the autocomplete field '...
0
votes
1answer
29 views

Form state cache breaks dependency injection [duplicate]

I have a class that extends FormBase and there are 6 services that are injected into the class via Dependency Injection (DI). My problem is when I submit the form it says to a class property that ...