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
2answers
533 views

Need to make Anonymous user create node through a Form but can't

I need to make anonymous user create a node through my site. The node which is create would be unpublished, which an admin can publish later. I wrote the following code which works perfectly but the ...
1
vote
1answer
547 views

Sending data via post and redirecting user

So I made a module that needs to gather some data and redirect user and that data to a payment site. function payment_upload_form($form, &$form_state){ $form = array(); $form['#action'] = '...
1
vote
1answer
561 views

How do I remove webforms from content types?

Currently, our site is built so that anytime a specific type of new content is created, the page automatically includes a form required for the end user. Due to tracking issues we're having with ...
1
vote
1answer
558 views

Use hook form alter to change input type

I am trying to change the input type on an ubercart checkout form using hook_form_alter. I added an extra field using the uc cart extra fields pane module but there is no option to add e-mail - only ...
0
votes
1answer
510 views

different form state redirects in a hook_form_alter

i have the code in template.php: THEMENAME_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'answer_node_form' && !isset($form['nid']['#value'])) { //dpm($form); ...
0
votes
1answer
509 views

How to display form element and label inline

This must be simple, but I cannot find the answer. I want the label and the textfield on the same line. I tried this: 'odt-filter' => array( '#type' => 'textfield', '#title' => 'Filtra',...
0
votes
2answers
522 views

Multiple forms and required fields affecting hook_form_FORM_ID_alter()

When creating a new content type, the $form_id is correctly picked up in my module. Let's say in my example, my form is called the 'foo_form'. The below hook_form_FORM_ID_alter function works fine ...
4
votes
4answers
5k views

I can't set a default value on hook_form_alter()

I have form alter for the user_register_form which is called. In this hook, I try to set a default value for a textfield but it doesn't work. I've tried all the syntax possible #default_value, #value, ...
1
vote
0answers
19 views

scrolling after posting drupal ajax form

I am working on an existing site which has a Drupal 8 multi-step form which uses Ajax Upon submitting the form (on the final step) the page scrolls to the top where a thank you message has been ...
0
votes
1answer
777 views

PHP Warning: Unknown: Input variables exceeded 1000 and how to fix

I have been working on a patch for https://www.drupal.org/project/hubspot for the 8.x version. In fact I found a ticket for this same error for the 7.x version (https://www.drupal.org/project/hubspot/...
1
vote
1answer
575 views

How to add custom input type button in forms?

I want to add custom input type button in form. I tried following code, but it is converting it to submit type button. How can i add input type button ? $form[custom_button] = array('#type' => '...
1
vote
3answers
535 views

How can I load entity form for comment?

I want to load entity form for comment entity type. I can load entity form for node (entity type = node and bundle = article). But the entity type = comment and bundle = comment. Here is the code ...
0
votes
0answers
32 views

Ajax implementation in exposed forms

We use to add property '#ajax' to a form element in our form array, to trigger an Ajax response and it works fine except in case of views exposed forms. This doesn't work in case of views exposed ...
1
vote
1answer
611 views

How to load field value to custom form?

I'm using Drupal 7 for my website. I created custom settings page with custom form in it, but the problem is I don't know proper way to load inserted value from database to my form after saving it, ...
0
votes
2answers
529 views

Save form when user refreshes page from browser or click on any anchor tag inside page

I have made a form in drupal. What I want is when the browser unload the page from any click whether by clicking on anchor tag or from browser refresh buttons I want to save data of my form through ...
1
vote
0answers
28 views

Have Value Selected but Label Showing in Views Display Plugin

I am working on a custom Display plugin for Views. In my buildOptionsForm() method, I have the following: $form['inherit_yaxis'] = [ '#title' => $this->t('The title'), '#type' => 'radios'...
0
votes
1answer
547 views

Field validation for real name - alpha numeric dash

I am using Realname module on registration form. I want to limit users to only user lowercase alphanumeric signs with dash instead of space. I have views that are not working good with arguments and ...
2
votes
1answer
1k views

Inline Validation Messages with Webform

Sorry if this has been asked before (although I've been looking and haven't found quite what I'm looking for). It's not currently possible to present the server-side validated messages (specifically ...
0
votes
0answers
640 views

“A fatal error occurred: Serialization of 'Closure' is not allowed”

I'm implementing a form using the Drupal form and AJAX. I've done this many times before, but now I stumble upon a problem I never seen before. My AJAX event is called when the value of a textfield ...
0
votes
0answers
22 views

How does the register form in the user module load ImageWidget?

I want to use the user picture widget on the user register form to capture an image. So for my custom entity form I'm using the managed_file as such modules/custom_module/src/CustomEntityForm.php ...
0
votes
1answer
655 views

Loading in iframe on ajax form submit

I've a form with couple of buttons, on submit it redirect to third party site for authentication. On the submit I want to load that inside iframe on same page. How I can do that?
0
votes
1answer
939 views

Dynamic dependent form select inputs

I'm building a custom dependent dropdown form with 2 select inputs. I've managed to build the form inputs and update them accordingly, but I'm not able to get the dependent select's value in the ...
0
votes
1answer
31 views

Provide autocomplete field with user's Display Name

Drupal core already supports autocompletion of username fields. However is there a way to provide autocomplete for user's Display Name? Since this is a virtual field, a database query with % like ...
0
votes
2answers
570 views

dependent dropdowns via #ajax for unlimited option

I have a commerce Product content type, which has a field collection field attached to it field_mycollection, which has 4 different fields field1, field2, field3 and field4 dependent on each other. ...
3
votes
2answers
2k views

How to attach token in a custom form field

I have a custom form in Drupal 8. I need to attach tokens for fields of my form. Basically I want to add "Browse tokens" option for each field of my form.
0
votes
1answer
607 views

Default value to 'datetime' field in form loaded from the database

I want to display the datetime field on my Drupal 8 form with some date loaded from the database, but the front end always shows empty fields as if no data has been provided. I tried several ...
0
votes
0answers
46 views

dependency injection by using $this when not in object context

if i´m using the codesniffer function i´m getting two warnings about: 155 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead If i´m changing the line from: $...
0
votes
1answer
541 views

How to submit form on selecting image in file select widget?

I am using Drupal Form API to upload profile image for user. I found two file upload widgets in FORM API: '#type' => 'managed_file' & '#type' => 'file' managed_file requires first ...
3
votes
2answers
2k views

Add javascript to returned form after ajax validation

I've built a form with the form API, and it's submitting via ajax via this type of thing: $form['submit'] = array( '#type' => 'submit', '#value' => 'submit', '#ajax' => array( '...
0
votes
1answer
669 views

How to add AJAX call back from another AJAX result in a form

I want to use 2 AJAX call back within a form. The scenario is like I am having a text field and a Search button which is defined in the form alter function. After entering a text and clicking on the ...
5
votes
7answers
8k views

How to place Contact form in block?

I have to embed a contact form inside of a block, and I'm trying to use the entity.form_builder service, But I'm not sure which entity I should give it, I found Message and ContactForm entity, so what ...
1
vote
2answers
756 views

Displaying the submitted values in a table

I created a custom form and after the form is submitted I need to display the submitted data in a table? This seems like a very simple problem. I am able to use dpm() and drupal_set_message() to ...
0
votes
1answer
1k views

Execute jQuery after form submit

I have a non-ajax form for which I'm trying to execute a jQuery function after the form has been submitted and processed. I don't need ajax for the form, but I do need to wait until 600 odd form ...
0
votes
2answers
533 views

Speech API Javascript and Drupal Forms

I'm using WebSpeech API to allow users speech recognition on my site. I'm using example 3 on this page: https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html. My code looks like this: ...
6
votes
2answers
2k views

How to customize the default search block form template?

How can I customize the default search block form template, I now use below template to display a search form block, but this code doesn't allow me to edit and customize each part of this form ...
1
vote
1answer
46 views

Possible to theme the form's elements with own twig?

I was thinking to get twig outputs so I could use these twig variables on a form.html.twig such as below: <div class="row"> <div class="col-md-6"> {{ form.name }} ...
0
votes
2answers
34 views

Can't find the cause of this error

I am working through a Drupal 8 module building exercise from YouTube and I am not able to figure out what is causing an error. The relevant page loads and displays the form but I get the following ...
0
votes
0answers
16 views

How to set a node as context?

I have a little web app where I have two node types: Customers (/customer1, /customer2) Notes about customers The notes about the customers have an entity reference to the customer. I like to create ...
0
votes
2answers
28 views

Ajax error render

I receive this error message when I try my custom form in Drupal 8. User error: "0" is an invalid render array key in Drupal\Core\Render\Element::children() This is the code I am using namespace ...
1
vote
1answer
552 views

How do I alter certain module form output

Some of my node types use fields from extra modules (such as Open Hours or Get Locations). How do I change the way those modules render their fields inside the form? I mean Get Location for example ...
4
votes
2answers
321 views

Detect when 'Remove' is clicked on a file widget form element?

I have a handful of file fields that have the following default Drupal behavior: User can upload a file User can upload another file in place User can remove file Standard config. Whats happening is ...
2
votes
2answers
367 views

How to add field to ALL webforms?

How do I add a field to all webforms? I have a website where I'm using webform for surveys and I want that on each survey there will be a field that is the same in all of the nodes/webforms. Thank you....
1
vote
1answer
563 views

How to copy select list value from a webform submisison into select list field new node?

This is the scenario: A webform with the following fields Question -> Textfield Category -> Select options (Listbox) Listing vocabulary HETCAT A content type Question with these fields Title ...
0
votes
0answers
18 views

Download a file and redirect to the form after batch operation

On submitting a form we need to run a batch process that writes to a CSV file. Once the batch process is completed we would like to download the CSV file automatically and redirect back to the form. ...
0
votes
1answer
24 views

Unset widget tab from media browser programmatically

Need to unset a widget tab from media browser based on the condition of media type supported by the field. Media types: Image and Video. For example, There is a field which references image media ...
5
votes
1answer
3k views

How do I load a form with a specific form display (form mode)?

On a custom page I'm trying to load an user edit form with a specific form display. I'm able to load the form however I can't figure out how to load the form with the specific display. This is what I ...
19
votes
6answers
20k views

How do I render a form?

What is the alternative to drupal_get_form('user_login'). in Drupal 8? I am using the following code in theme_name.theme, but it doesn't work. // Include namespace for userLoginForm. use \Drupal\...
0
votes
1answer
569 views

Computed value on multipage Webform

I have multipage webform. I want to compute the value of the component (Hidden -type) which is on the second page based on the data submitted on the first page. I'm using hook_form_alter and added my ...
1
vote
2answers
594 views

File Upload Field not working

I just tried to create a simple mandatory file upload field in a custom form like this: public function buildForm(array $form, FormStateInterface $form_state) { $form['#attributes'] = array('...
0
votes
2answers
2k views

How to use managed_file to upload many files

I'm looking for a way to upload many files by means of the managed_file form API element. I would like it be like while uploading for node where is 'add new item' button. How to do it?