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
0
votes
1answer
31 views

Select all checkboxes of an entity reference field on creating a node

Drupal 8.7.x For one of my content types I have an entity reference field referencing a taxonomy vocabulary. I have a lot of terms in this vocabulary which makes it tedious to check all the ...
1
vote
2answers
659 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 #...
-2
votes
0answers
34 views

How can I allow only one selection using checkboxes, not radios? [on hold]

Maybe I'm reading documentation wrong. Shouldn't this code: $form['packet_pickup_checkboxes'] = [ '#type'=>'checkboxes', '#options' => [ 'self' => 'I will pick up my own packets',...
1
vote
2answers
2k views

Any chance for alter system settings form via hook_form_alter?

I would like to create module based on other custom module. One thing that will be nice to able to do is to alter module settings form fields. Is this possible?
1
vote
1answer
419 views

How to add an autocomplete field to a form

I've got a page that, in response to a button click, brings up a Bootstrap modal form. In that form is a textfield with the standard Drupal autocomplete behavior; it's working fine. I now want to ...
1
vote
1answer
604 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 ...
2
votes
3answers
3k views

How should I perform a redirect in hook_form_alter()?

When users log in, I want to redirect them to another page, when they have a certain role. In Drupal 7, I'd use drupal_goto() in hook_user_login() to do the redirect, and hook_module_implements_alter()...
0
votes
1answer
423 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 ...
1
vote
2answers
420 views

Change the value of a field depending on the selection of another

I need to change the value of a field based on the selection of another. I also don't want the user to have the ability to change this value. I tried using #disabled = true, but the values don't ...
0
votes
1answer
526 views

Field Entity Autocomplete filter the published nodes

my problem is that I have a custom form with an autocomplete entity field for the search. The problem is that the field shows me both the published fields and those that do not. Is there any filter or ...
0
votes
1answer
482 views

Form and gated content

UPDATED from earlier: I am using a simple Drupal form that collect user info before allowing the user access to donwloadable content. NOTE: This is using the form API and I am no longer using a modal;...
2
votes
1answer
428 views

Adding fields via ajax in form does not show in arrays in form_submit

I have am trying to add fields to a form in drupal via ajax. I am able to have my fields show up on the form without issue but the problem is seeing values of those fields when the form is submitted. ...
0
votes
1answer
464 views

comment form custom validation

I am using a custom validation in my Drupal 7 comment form.I want to match the comment_body against a word "example" so if someone just type "example"in the comment body then it will show a error ...
1
vote
1answer
491 views

form_alter and #element_validate inside .module file

Inside my .module file, I have created a hook for alter register_form and add a password field with a custom field-validation: function xenforo_form_user_register_form_alter(&$form, \Drupal\Core\...
0
votes
0answers
24 views

Webform Multi-step validation

I have a multi-step/page webform. It works fine. I have on one page two date fields. One field must be on or after the other and thus I want some validation. No problem I followed the tutorial ( How ...
1
vote
2answers
564 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 ...
1
vote
1answer
414 views

Change mark-up with a textfield using Ajax

In a form I have a field where the user have to enter the name, after this I have to update a markup with data from an external DB using the textfield as a parameter, How can I do this or even Is this ...
0
votes
2answers
456 views

Why can't I modify my comment form using hook_form_alter

I have enabled comments for a custom node type. I am trying to theme that comment form using hook_form_alter(&$form, &$form_state) (For example, I'd like to remove the label of the ...
3
votes
1answer
432 views

Vertical Tabs in Panel Pages

I am trying to have three forms available to the public on my site and would love to have them configured in in the vertical tabs layout. Initially I was going to have them available through node/add/...
0
votes
2answers
321 views

Altering Views Exposed Form Elements and their Associated Labels

I have a series of Views Exposed Forms across a Drupal 8 website. My goal is to generate unique template suggestions so I can theme each individual input and their labels differently as needed. Here ...
0
votes
3answers
3k views

download file on form submission

I have created a form which has only a submit button. In the submit function I am generating csv file and saving it to the files folder using fputcsv function. But Now I need extra functionality of ...
0
votes
1answer
1k views

How to stop a form refreshing after callback

I have a form, which is made up of a listbox and a textarea, the listbox holds a number of items that related to records in the database. The user can select an item from the listbox and select the ...
1
vote
2answers
488 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 ...
0
votes
1answer
405 views

Send data with post to other drupal page not working

I'm trying to send data from a html form to another drupal page. The Form (in JavaScript): var data = { // JS Object with data to send priceUnit: '131.97', priceTotal: '131....
1
vote
1answer
451 views

Form submit POST renders page before submit handler is called

I have a search form in the header that is simply adding a search term to the current URL. If you are on example.com/list-page and submit a search, it just sends you to example.com/list-page?search=my-...
-3
votes
1answer
51 views

The form has become outdated. Copy any unsaved work in the form below and then reload this page [closed]

How I can fix the error? The form has become outdated. Copy any unsaved work in the form below and then reload this page. I get the error when I try to render a form in another form. I think it can ...
2
votes
1answer
453 views

Submitting a form causes 'secure connection failed' error that persists

I've got a SSL certified server running drupal 7.37. Everything was working fine until I started adding form submission to a module I'm working on. As soon as I submit the form, I get 'Secure ...
4
votes
3answers
1k views

Cannot deal with multiple iterations of same form on one page

I am designing a site that has a variety of points in which I need to render "workflow" buttons that are used to send actions to an external application. I used the form API to generate these ...
0
votes
1answer
342 views

Return Table and Form in page callback

I have a problem returning table and form in page callback at the same time it only works if one of them only returned. function _table_maps(){ $query = db_select('maps','m'); $result = $query->...
4
votes
6answers
12k views

How can I add a cancel button to the content add form for a single content type?

I have several content types on a site and most of them are user-editable but not user-creatable. However, one content type, Image, allows users to upload a picture. Sometimes, however, users upload ...
2
votes
2answers
470 views

How to redirect to a different URL based on node content while loading a node

I have a site that uses the webforms module to gather user information. On the front page there is a list of previous submissions. Each of which has a link to view the submission (generated by Views ...
1
vote
1answer
55 views

entity_autocomplete field thats added by ajax is not working

I have a field im adding to a node-edit form by ajax. the field is a simple taxonomy auto-complete field. when I add it directly in my form_alter it works, but when it's added by ajax, The ...
0
votes
3answers
40 views

Can I create a form with a route like this /rooms/{node.alias}/booking?

I'm working on a booking project and I have to create a form for reservations. I have created the accommodation content type and the url_alias for this is: /rooms/[node:title] Example: /node/1 = /...
3
votes
3answers
989 views

Adding accept attribute to managed_file field to specify file types client-side

I've got a file field in a custom form like this: $form['image_upload'] = array( '#type' => 'managed_file', '#title' => t('Image upload'), '#description' => t('Upload png ...
1
vote
1answer
404 views

Form field not show on Ajax Callback even the callback is called

I have a form with one shown field of type select with ajax callback to show another form field dynamically of type select and with ajax callback again, the problem is second field ajax callback ...
0
votes
2answers
467 views

Drupal Date Popup - Disable Selects, Display names only

I am looking for a way to remove the select dropdowns from the datepicker popup and only display the names of the months (and the year). As for the appearance it can be altered in datepicker.1.7.css . ...
0
votes
0answers
18 views

dropdown multiple values

I am trying to display multiple values of drop down and store it to the database. How could I do that? Any help would be appreciated. $form['options'] = array( '#type' => 'value', '#...
1
vote
2answers
100 views

Change remove from cart button to an image button

I want to change the remove-button, that removes line items from the cart to an image button representing a trash can like this: The code I am using in a custom module looks like this: <? php ...
0
votes
1answer
464 views

Allow user to fill out node form, then force registration

I'm making a classified website. Have a button that say "Make a ad" I would like the Anonymous user to be able to fill in the text for the ad. But the Anonymous users after filling in advert. has ...
0
votes
1answer
17 views

Is there any elegant way of excluding form element from the `values` array of the `FormState`?

I know that the values array can be cleaned up in the validation or submit callback, but can we somehow mark the element itself to be not put in the values array of the FormState?
3
votes
2answers
45 views

Unable to retrieve uploaded file in submit handler

I'm creating a custom form with a file upload field that will have its contents read, processed then sent to an external API. The problem is whenever I upload the file the field for it appears to be ...
0
votes
0answers
14 views

How can I display custom error message using ajax submission?

I use the following code to submit form data using ajax: <?php namespace Drupal\ajax_form_submit\Form; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\...
3
votes
1answer
452 views

How do you keep the login block on the same page when validation fails?

On pages where the login block exists, I need to stay on that page (and preserve query string arguments) if the validation fails when submitting the form. Does anyone have any idea how this could be ...
0
votes
2answers
777 views

Setup custom required field validation for a field in custom form

How can I setup custom required field validation message for a text field in my custom form. I tried below code. But it is not working. It always showing 'Please fill out this field'. $form['...
1
vote
1answer
577 views

How to properly check in entity form validation if field is empty?

I have a content type "A" (Node entity type). In it's node form (new/edit) I need to check if some fields are empty or not (which are not required in general). My first intention was to use FormState "...
0
votes
0answers
26 views

How to wrap Paragraph fieldgroup horizontally

I want to display a few fieldgroups inside of a Paragraph side-by-side horizontally when in node edit form. I gave each fieldgroup the class .popular in the GUI in manage form display. The fieldgroup ...
1
vote
2answers
449 views

Multipage registration form with Ctools

I'm trying to follow the tutorial on multipage user registrations at http://www.grasmash.com/article/building-multistep-registration-form-drupal-7-using-ctools, but I'm doing something wrong. As it's ...
1
vote
1answer
2k views

Get $form_state values from individual entity form fields

I have a weird use case. I created a custom form with some fields and I added some other fields from one entity form like this: public function buildForm(array $form, FormStateInterface $form_state) {...
2
votes
1answer
1k views

How to alter views exposed form and add ajax to filters

I have a views with 2 exposed filters - both taxonomy reference, select. I want to limit options in second filter based on user selection from the first. Tested with enabled/disabled ajax in views - ...
0
votes
0answers
5 views

How do I save a file's path in a view's plugin module scenario?

I'm building / improving an existing custom module that initially allows a user to select a CKeditor textarea as a Header for any view, where every single view can all have different images. My goal ...