Questions tagged [forms]
Use it for questions about the Form API. Don't use it for entity or entity field forms.
6,767
questions
0
votes
1
answer
508
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
1
answer
947
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 ...
1
vote
1
answer
774
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 ...
0
votes
1
answer
409
views
custom module to create multiple forms with pop-ups
I am working on a custom module to create a form. Functionality of the module is as follows: The first form has an url, on clicking the url it should show another form as a pop-up.
How can i call ...
0
votes
1
answer
1k
views
Render form with ajax submit
I have a custom form in a module, similar to this example:
function mymodule_form($form, &$form_state) {
$radio_options = array(...);
$form = array();
$form["wrapper"] = array("#markup" =...
1
vote
1
answer
956
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
1
answer
1k
views
Multiple Different AJAX Enabled Forms on the Same Page
I currently have a form that is being loaded by AJAX and is working perfectly. I now need to add a second form (Add Single Stat) to the same page via AJAX as well. The Add Single Stat form is being ...
0
votes
1
answer
1k
views
How can I set value to hidden field (Form Api) and send them with post method?
I’ve created a form with Form Api in a custom module.
I send datas with post method to a web service.
In buildForm()
$form['mode'] = array(
'#type' => 'hidden',
'#value' => '...
0
votes
1
answer
372
views
How to set default value for entity reference programmatically in a form?
I have a custom form that I created programmatically.
$target_type = 'node';
$selection_handler = 'default';
$selection_settings = ['page'];
$data = serialize($selection_settings) . $...
0
votes
1
answer
481
views
Use ajax to save modal / dialog form instead of page reload
I'm looking for a way to save modal & dialog forms through ajax instead of redirecting the user after the form submit. Ajax is quite unknown territory to me.
I've found several interesting topics ...
0
votes
1
answer
21
views
Form field states with media fields that use media library widget and conditionally displaying visibility based on other media fields
I am trying to get some media fields to hide/show conditionally using $form fields #states API, based on other media fields (all the media fields are using the "Media Library" widget in form ...
0
votes
1
answer
894
views
Custom Ajax forms with managed_file form element
We have a form with three fields - where depending on the value of the first select field, we will show the other two form elements - one select field (the options depends on the value of the first ...
1
vote
2
answers
889
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 ...
3
votes
1
answer
509
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 ...
4
votes
1
answer
913
views
Prevent dual submit on form submission
I've got a form that submits via AJAX and in the callback I need to rebuild certain parts of the page to reflect the newly submitted data. One of these parts is the form, which I need to clear all ...
1
vote
1
answer
820
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['...
1
vote
2
answers
1k
views
Redirect to Different URl on validation errors in form builder
I am using drupal 8 fapi and i have user case as below
I have a form on https://example.com/landing-page and I submit the form and there are validation errors .the page should reload as https://...
0
votes
1
answer
2k
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 ...
0
votes
2
answers
359
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 ...
1
vote
1
answer
421
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
1
answer
1k
views
How to display a form in controller method
I have a form defined in mymodule/src/Form/myForm.php
namespace Drupal\mymodule\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class myForm extends FormBase {
/**
* ...
1
vote
1
answer
485
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 ...
0
votes
1
answer
623
views
Pager not working when $form['table'] is called with AJAX
For a statistics page I let users select the right file in a select list. After that I generate a table with stats. This table also has a pager (that worked without the ajax part).
Now I did ...
2
votes
2
answers
521
views
Add a class the the form element (tag) of the search block form
How do I add a class to the form element of the search block form?
I mean, add a class to this element:
<form action="/search/node" method="get" id="search-block-form" accept-charset="UTF-8" data-...
1
vote
1
answer
521
views
Add taxonomy term in popup
I have a select list with some options. But now I also want an option Other. And when you select the Other option there has to open a pop-up screen with the add term to vocabulary form in it. The term ...
0
votes
1
answer
805
views
How to remove a term programmatically from entity reference field using entity browser on translation form?
I have a content type "Articles", this is a multi-language site, by default the content is created in English, and then translated into Spanish. On new article in English, I set a title and a term for ...
1
vote
1
answer
417
views
How to specify entity reference fields when programmatically submitting to user_register_form
You'd think this would be easy. I'm calling drupal_form_submit('user_register_form', $form_state)
to automatically register users after they have completed filling out a Webform.
But I have some ...
0
votes
1
answer
493
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.
...
0
votes
1
answer
424
views
form #type => checkboxes with zero / empty option value
I am building something which uses a form element with '#type' => 'checkboxes'.
I want this to be reusable, so it should accept anything as option values that works as a PHP array key (integers ...
1
vote
1
answer
981
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 ...
1
vote
2
answers
475
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
1
answer
557
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
1
answer
390
views
getStorage() on null when using entityTypeManager in form
I'm trying to use dependency injection correctly in a custom form but I'm getting an error when trying to access entityTypeManager.
<?php
namespace Drupal\my_module\Form;
use Drupal\Core\Form\...
0
votes
1
answer
1k
views
How to get the file ID using managed_file on custom form?
In Drupal 8, I have a custom form that I built using the Form API in a custom module. I am trying to upload a file using managed_file field. For some reason I can't get it to give me the file ID no ...
0
votes
1
answer
464
views
How do I override /theme/custom twig in my module to render input fields?
I have a module that is building a form. I want to theme the form using twig within my module so it does not interfere with my theme/custom twigs.
My buildForm function is:
public function buildForm(...
2
votes
1
answer
762
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
1
answer
481
views
Render array doesn't render children
I can't add a form to a node. Using the following code, the generated HTML show only the node. If I return $form, the form is rendered correctly. What is my mistake ?
function hook_menu() {
$items['...
0
votes
2
answers
748
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 ...
0
votes
1
answer
401
views
How to make uploaded file permanent to node without node submit
My module automatically save new empty node when user create new node and redirect to edit this node. Now, is it possible to make uploaded file on _node_edit form without submitting form?
edit:
When ...
0
votes
1
answer
519
views
Change theme template for one form
I try to change a the theme template for one form. I do not want to use theme suggestions as I only want to use a different theme in one case, and if I add a suggestion, it is always used. (maybe I'm ...
0
votes
0
answers
20
views
Html5 tags and javascript stripped out form radio labels
On D7, I have the following simplified code
function mymodule_multistep_form($form, &$form_state, $vars) {
$mystatictext = get_my_static_text($vars);
$options ='<div class="...
2
votes
2
answers
500
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 ...
0
votes
2
answers
1k
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 ...
1
vote
1
answer
505
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
1
answer
621
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 ...
0
votes
0
answers
24
views
not able to use logger in a class /closed
I have a quick question. (drupal 9)
I'm working inside a custom form class (custom_module/src/Form), in a public function.
I want to log some values so I can debug, but the default Drupal logger is ...
0
votes
1
answer
832
views
Trying to pass id to the ajax callback function, keeps overwriting, how to solve this?
I created a form which have a lot of images and a delete button on every each one of them. I used ajax to create a callback function which would delete the image. Here is part of my form:
foreach($...
0
votes
2
answers
2k
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
0
answers
12
views
How to set media field mappings to autofill the target fields when uploading the file instead of saving to those files when saving the media entity
I am using the document media type for pdfs. I am also utilizing the field mappings for:
Name
MIME Type
File size
and I will be adding a field mapping for the pdfs subject as well using a Media ...
0
votes
2
answers
544
views
Form API Field Permission
I am creating a custom form and storing data in custom table. I was wondering if there is any method to apply field level permission like
$form['value']['#permission'] = array('access this field');
...