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
-2
votes
0answers
11 views

How to add entity reference field to a form by coding?

I created a form in my Drupal 7 project and I have added some fields. I want to add an entity referenced field to my form programmatically. I searched a lot but I found no result. entity referenced ...
0
votes
1answer
926 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
1answer
413 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 ...
1
vote
2answers
417 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 ...
1
vote
1answer
414 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 ...
0
votes
0answers
30 views

Save value in form with multiple instances in same page

This is my buildForm function: class NewsletterForm extends FormBase { // ... public function buildForm(array $form, FormStateInterface $form_state, $newsletter_list = NULL) { $form_state->...
0
votes
1answer
403 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....
0
votes
1answer
491 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 ...
1
vote
2answers
457 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
2answers
431 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
2answers
2k views

How to create a “go back” or “cancel” button on the node add form?

I'm trying to add a "cancel" button to my content type. In hook_form_alter(), I'm using this code: if ($form_state->getFormObject()->getOperation() == 'default') { // On node add, make it ...
0
votes
1answer
479 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;...
0
votes
1answer
462 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 ...
0
votes
0answers
21 views

Ajax based form doesn't work on new from element [duplicate]

I am creating some dynamic form element based on the dropdown selection. There are max 3 dropdowns and I want to run ajax on each dropdown on change event. When I clicked on the first dropdown(Level ...
2
votes
2answers
465 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 ...
2
votes
2answers
943 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 ...
1
vote
1answer
356 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 ...
2
votes
1answer
402 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 ...
1
vote
1answer
32 views

Focus problem when Ajax call for multiple fields calling the same callback function

I have implemented a custom form. I put same Ajax callback function for multiple field. When one Ajax call completes, I click on other field. But I can't unfocused previous field. Sometimes the Ajax ...
0
votes
0answers
21 views

Get key of select list in webForm

For example, i Have webform There is a field with 3 options in allowed values, like option1, option2, option3 i want if i select option 1 get key of option
1
vote
1answer
449 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
2answers
453 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
10 views

Uploading xlsx-file changes permissions of the file? Errors when loading via PHPExcel

My goal is to let the user upload a xlsx-file and then read the file to create objects. So i created a file upload page in my custom module where the user can upload a file via the 'file' form field ...
2
votes
3answers
2k views

Custom form submit handler is called, but node is not saved

There are many questions about a custom form submit handler not being called, but in my case, the handler is being called; however, the entity is not being saved. Specifically, I have a custom submit ...
2
votes
2answers
1k views

Dependency injection not working custom form

I have a custom module with a form class, where I am trying to inject a custom service to use within it's submit method: namespace Drupal\my_module\Form; use Drupal\Core\Form\FormBase; use Drupal\...
0
votes
2answers
468 views

How to restrict previous date display in custom forms?

I created a custom module for a form which accepts from date and to date as user input. I would like to restrict the user from selecting a date prior to current date. Code snippet of my code $form['...
0
votes
0answers
10 views

Set a field value with FAPI states

Does anyone know if there is a way to set the value of a field with states? E.g. If "this" is checked, set input value to "0" Something like.... $form['booking_process'] = array( '#type' =&...
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. ...
1
vote
1answer
445 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-...
0
votes
0answers
25 views

AJAX in callback function

I'm trying to convert old code written in standard HTML/PHP/Javascript/JQuery into a format (more) consistent with Drupal. The code consists of a form with interactive elements (regulated by ...
0
votes
1answer
38 views

Hide fields in Paragraphs conditionally using Form API #states

Because the Conditional Fields module doesn't work with paragraphs for Drupal 8, I've followed the instructions in Conditional Fields in Paragraphs Using the Javascript States API for Drupal 8 to hide ...
0
votes
0answers
46 views

Why Form Api behaves differently in route and in custom block?

I’ve encountered this issue several time and I don’t know why. I know this not so easy to reproduce but maybe someone has an explanation. I’ve built several custom modules which return datas from ...
0
votes
0answers
17 views

Custom field validation condition not working

I have created a custom form validation. I am using webform module to build the form. in _achva_tz_validate function there are two fields that have the same validation. The second field, zug_id, is ...
0
votes
2answers
469 views

How to send email to submitter in a webform?

I have a webform and i want to send by mail this webform to submitter. For the moment, i created an hidden field with token [current-user:mail] and i chose this field in adress. I think it isn't very ...
0
votes
1answer
33 views

hook_form_alter() on a view exposed filter form

I am trying to add a disable attribute in a field using the hook_form_id_alter function. I created a module and built the function function disableIncentiveform_form_views_exposed_form_alter(&$...
3
votes
1answer
430 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/...
2
votes
1answer
417 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 ...
0
votes
0answers
13 views

Adjust block according to stage in multi-step form

I've build a multi-step form using the following tutorial. Which is quite nice! Can I also change a block based on the step you're in? I'm my case I have an activity registration form, build ...
1
vote
1answer
518 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 "...
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 ...
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'...
3
votes
1answer
447 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 ...
2
votes
1answer
497 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
1answer
19 views

Skip a form step programmatically in simple_multistep module

I am trying to skip a step in multistep node form using Simple Multistep module. I have tried following snippet that works pretty good to skip one step. $skipStep = $form_state->get('...
1
vote
3answers
587 views

Form custom with method GET remove form_build_id and op from GET variables

If I create a custom form with get method: $form['#method'] = 'get'; When I click the submit button, many variables are populated with GET Can I remove them cleanly according to the drupal logic?
0
votes
1answer
483 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
2answers
27 views

How do you use hook_form_FORM_ID_alter() to alter the USER EDIT form?

I'm trying to mark fields on the /user/_uid_/edit screen as disabled. These are custom fields I've created in /admin/config/people/accounts/fields in D8. I have this code for another node entity type....
0
votes
0answers
16 views

Cannot get form values set in a ajax callback

In the hook_form_alter, I add 3 textfield form elements and 1 button with ajax callback: function zwznertags_form_alter(&$form, &$form_state, $form_id) { if($form_id == 'book_node_form') { ...
0
votes
0answers
33 views

Delete records from database pressing a button in twig

Drupal version: 8.7.x I created a module that retrieves meals based on the given ingredients. I display the ingredients with a delete button and the meals underneath them. However I don't know where ...
0
votes
2answers
459 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 ...