Questions tagged [forms]

Don't use it for entity or entity field forms.

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
3answers
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
439 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
9 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
444 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
19 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
21 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
43 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
13 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
461 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
24 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(&$...
0
votes
0answers
11 views

Email misses fields from form

This is regarding a Drupal 8 site, specifically Drupal 8.7.1 and the "Contact" module (with Contact Emails, Contact Storage enabled). The issue that I'm running into is some of the fields are not ...
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
506 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
446 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
1answer
60 views

How do i use onHourShow callback in a date_popup control with the Form API [closed]

On my form I have a date_popup control: $form['order-group']['delivery'] = array( '#title' => t('I Need The Equipment Ready By'), '#type' => 'date_popup', ...
2
votes
1answer
496 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
13 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
561 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
480 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
23 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
15 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
30 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
456 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
1answer
515 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
478 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
0answers
19 views

How can i do Webform field custom validation

I want to do a custom validation for a field in some of my webforms. I came across this code: https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-...
0
votes
1answer
469 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 ...
0
votes
1answer
463 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
668 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){ ...
1
vote
1answer
459 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 ...
1
vote
0answers
92 views

Why isn't my custom Form API #states applied in my webform yaml editor working?

I have the need to set visibility state of a checkbox option in one question (Table checkbox select) based on the value of another checkbox in the same table. I also have other scenarios where I would ...
0
votes
1answer
31 views

SOAP with custom form select

I'm getting results from a SOAP call, but cannot display the values in a select list on my custom module. This is a part of my code: foreach($sxml2->NewDataSet->DepCity as $item) { $...
0
votes
2answers
1k views

How do I add a JavaScript file to a form?

I'm trying to add a JavaScript file to a form that I have in a modal. Although I followed the information found here, here, and here, the file doesn't appear in the Network tab of the inspector and ...
2
votes
1answer
2k views

How do I extend a configuration form without using hook_form_alter()?

I want to extend some fields in a config form of a module with another module in Drupal 8. I created a config form in a module (e.g. custom_1) and now I want to add some more fields from another ...
0
votes
1answer
16 views

Form with manged_file filed is not submitted?

I have a form in my drupal module. in my form, I have used manged_file field. form name is "difference_form" and I have created two functions. one is "function diffence_form" for form definitions. ...
0
votes
1answer
492 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 ...
1
vote
2answers
687 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
1answer
849 views

Display date picker not inline in Drupal 7 Forms API

I have installed Date Picker Module and it works fine. Below is the code: $form['date'] = array( '#title' => t('Select your birthdate'), '#type' => 'datepicker', '#date_format' =&...
1
vote
1answer
172 views

Converting UTF8 Data to SQL_ASCII

I want to convert my query results from a database, which is SQL_ASCII database encoded, to UTF-8. $result = $query->execute; $converted_data = array(); foreach($result as $record){ $...
3
votes
1answer
441 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
494 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 ...
0
votes
0answers
20 views

How to set an array of hidden form fields using $form_state->setValues

I want to set hidden fields (permission by field) of a form in Drupal 8. The fields in the form have the names field_pbf_municipality[0]['target_id'] field_pbf_municipality[0]['grant_public'] ...
0
votes
2answers
583 views

How do I implement the login, register and “Forgotten password” forms?

I'm trying to implement the three Drupal 8 user forms : login, register account and forgotten password forms. I'm creating custom pages in my module for each one of them because I want to display ...
0
votes
1answer
499 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 ...