Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [forms]

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

0
votes
1answer
14 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. ...
1
vote
0answers
33 views

How can I apply my own Form API #states to an existing webform?

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
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
683 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
841 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
167 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
488 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
17 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
569 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
496 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 ...
0
votes
1answer
24 views

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

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', ...
0
votes
0answers
20 views

Modifying Page Title To Be Separate From Browser Title [duplicate]

I have a module that contains multiple forms, each form in its own file. I need to modify the page title such that it is different from the browser title for several of these pages. The name of the ...
-2
votes
1answer
22 views

Remove or prevent theme CSS styles on specific form elements

Is there a way to create a form element and prevent Drupal from adding classes by default? I have elements that are highly customized. My theme assigns classes by default that ruin these specifically ...
0
votes
0answers
17 views

Drupal 8 : Multiple Submit Handler

I am using Drupal 8.6 for creating custom module in Admin. I have a custom form where i have to use multiple submit button for form submission. I am not able to submit the my form to specific function....
-1
votes
0answers
18 views

Select options shown in wrong order [on hold]

So I have a form element like this: $form['country'] = array( '#type' => 'select', '#options' => mymodule_country_select_list(), '#title' => t('Country'), '#required' => TRUE, '#...
0
votes
1answer
701 views

How do I throw values calculated back to buildForm()?

I am trying to throw back values that are calculated in submitForm() to buildForm(). How do I add more state values into it? /**  * @file  * Contains \Drupal\resume\Form\ResumeForm.  ...
3
votes
2answers
48 views

How to prohibit some words and letters to use as a Drupal password? [closed]

I need to prohibit a user from using a few words as a password. E.g I don't want to use these words as a password. Drupal, 123456, Microsoft. When a user submits the registration form with the above ...
1
vote
1answer
460 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. ...
0
votes
0answers
42 views

Ajax dependent drop down not working on form rebuild

I have a drupal custom form with two ajax dependent dropdown fields and five normal text fields. on form submit, all things are working fine except validation of form fields. when I put validations on ...
0
votes
1answer
338 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 ...
0
votes
2answers
716 views

Form alteration is not working from within my form class

I am following https://www.drupal.org/docs/8/api/form-api/introduction-to-form-api for my hello world module. Below is my code namespace Drupal\hello_world\Form; use Drupal\Core\Form\FormBase; use ...
5
votes
7answers
17k views

How to add reset button to forms?

I've been researching this matter for a while with no clear answer yet. So, here are a few questions ... I'm assuming (correct me if I'm wrong) that Drupal 7 doesn't support reset buttons. It ...
-1
votes
0answers
9 views

Can't able to add Drupal 8 Commerce PayPal Checkout details [on hold]

I'm trying to add paypal module in drupal 8 commerce functionality. And i downloaded paypal 8.x-1.0-beta4 version then installed and enabled. After that i trying to add paypal checkout payment gateway ...
0
votes
2answers
642 views

How can I dynamically disable a single required field from validation in a form?

This is an extension of this question: Need help with AJAX callback function for text field validation in form_alter I have a form with a Username autocomplete field (txn_user). The editors want to ...
1
vote
1answer
480 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
1answer
596 views

Allow special characters in the Search Form

I can't search with any special character in the default search block form or in search API. Commonly used word like B&W (black and white) don't seem indexed up well, probably due to some encoding ...
0
votes
1answer
342 views

Checkboxes, Radios, 'select or other' wont render inside table select element

I want to render elements of type checkboxes or radios inside tableselect, but what I get are empty html tags. Textfield and select type elements render fine. Basically this renders fine. $...
0
votes
1answer
339 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->...
0
votes
1answer
21 views

How can i add ajax callback to checkbox in drupal form?

I am using taxonomy manager module I want to add ajax callback to checkbox tree view for checkbox is checked condition but it is not working can some one please suggest me. I have modified the code ...
0
votes
1answer
24 views

How to add unique class to each checkbox elements

I am displaying checkboxes using form API in Drupal 8. For functional and theming purpose I need to add unique custom class to each checkbox element. Is there any way to add classes to each checkbox ...
-1
votes
2answers
473 views

Why block with add node form returnes errors?

To show add node form in particular place I created a new block on the Block page with content: <?php global $user; module_load_include('inc', 'node', 'node.pages'); $node = (object) array('uid' ...
0
votes
2answers
655 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['...
0
votes
1answer
497 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): $...
2
votes
2answers
1k 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' => ...
0
votes
0answers
26 views

Initial values in forms elements

When I create a form (using form api) I need, sometimes, to assign a default value to form elements, or to create a list for select elements, under certains conditions. In this cases, I need to do ...
1
vote
1answer
340 views

How do I replace part of a webform component label with a variable token?

I have webform component labels like this: Did [your pet] have any illnesses? and I want to replace [your pet] with a variable token? Do I need to write a custom module or can I do this by editing ...
0
votes
1answer
582 views

Custom form validation

I've created a custom module for populating a database and now I need to apply form validation to this form. I want a few different validation things to happen. I want to limit specific entries on ...
2
votes
3answers
519 views

create a custom form based on user fields

I created new menu item witch I want to insert a custom form to edit some user fields : $items['user/%user/edit-custom'] = array( 'title' => 'Knowladge', 'page callback' => '...
3
votes
1answer
515 views

How to add javascript after form was validated with ajax callback?

I created a simple form. How could I add JavaScript commands after form was validated? Why is it so hard do this? $form['submit'] = array( '#type' => 'submit', '#value' => 'submit', '#...
3
votes
4answers
3k views

How do I change the default value of a field with AJAX?

Related to my previous question: Form fields created via Ajax are missing element attributes I have a date field and a series of text and number fields which need their default values to change based ...
0
votes
1answer
340 views

How to show a custom form in a block?

I have a custom form which currently shows on a page. The form is submitted via ajax and the view embedded is also updated via ajax. I do not want to show the form on a page. Instead I want to show it ...
0
votes
1answer
478 views

Profile2 regpath move account email field, into profile2 form and handle submit

I have a profile2 regpath displaying my profile2 form, and the system default account registration form below it. I need to move the account email field up into the container with the profile2 fields. ...
1
vote
2answers
491 views

HTML Form that Passes Information to Hidden Fields Through URL

I am trying to build an html form that is stretched across several pages. My intention is to use the GET method to send all of the fields data in the query string (URL parameters) and then store this ...
19
votes
7answers
34k views

How do I add a custom validation handler to an existing form/field?

How do I add a custom validation handler to an existing form (or form field) in Drupal 8? I have a form that I haven't created. I want to add my own validation rules on some fields when the form is ...
0
votes
1answer
32 views

How to modify a form to have some field surrounded by 'Details'?

I created a custom content entity with Drupal Console. Three of its fields are defined this way: // ---------------------------------------------------------------------------- $weight++; $...
2
votes
2answers
311 views

Autocomplete textfield displays value when selected and not label

I have a textfield autocomplete field that shows a list of full user names and email addresses as designed but when a user is selected, the user id is displayed in the field; not the name and email ...
2
votes
2answers
208 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
483 views

How to get the managed_file progress bar working in a custom theme?

I'm trying to get the managed_file progress bar working in a custom theme. Right now, when I start an upload, the empty progress bar widget appears in the form, but it doesn't visually update while ...
1
vote
1answer
505 views

Alter label with token

I am trying to build a questionnaire that simply replaces (alters) the label of a list-field. I´m doing so by replacing a token from views (embed) and using a hook_alter_form function in an separate ...