Questions tagged [forms]
Use it for questions about the Form API. Don't use it for entity or entity field forms.
1,868
questions with no upvoted or accepted answers
7
votes
0
answers
538
views
Execute form custom validator first before default validation
I have added a custom form validation on node/add page in drupal 8. The purpose of adding this validator is to add a slash before the path alias string. By default if a path alias string is added ...
6
votes
0
answers
289
views
How to get referencing parent entity when adding entities via Inline Entity Form to set automatic titles?
I have a content type "Parent" and a content type "Child". When adding Parents, the user can add Childs via Inline Entity Form.
Child content types have Automatic Entity Label enabled. In that ...
5
votes
1
answer
144
views
Programmatically Setting Content Ranking Factors For Drupal Search
I've added a dropdown to Drupal search page interface. I would like for users to be able to select this control to sort results according to Date or Keyword Relevance.
I'm able to get the dropdown ...
5
votes
0
answers
340
views
Is there any way to add a file field for multiple upload file to a custom form?
I'd like to add a file upload widget to a custom form, with core file module, as shown in the admin edit node page. I've trying with the 'managed_file' API, but I've only got upload one file. I need ...
4
votes
0
answers
110
views
Can TableSort honor form rebuilds?
I have a Form route in a site I am working on that is doing an entityQuery and displaying tabular data with some form elements to provide filtering, but without paging. For various reasons I can't ...
4
votes
0
answers
1k
views
Loading a form in dialog/modal returns an error
I have a form with a submit button binded to an AJAX callback that opens up a modal with another AJAX form. The modal dialog opens with the form, but the AJAX submit in that modal form isn't ...
4
votes
1
answer
964
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 ...
4
votes
1
answer
1k
views
How to set a default value for Simple hierarchical select?
I tried to implement hook_form_alter in order to pass default value to Simple hierarhical select views exposed filter.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
$tid = ...
4
votes
3
answers
5k
views
Node add form alter & submit custom field
I have a content type "event" with a field called "field_pricelist". It's a dropdown with no values, I add the values when I alter the form. The values come from a custom table (install / schema) in ...
4
votes
2
answers
2k
views
Alter granularity in date exposed filter from Y-m to Y if only year is selected
I am trying desperately to get the following working:
Goal:
I have a views that displays a list of events. To this views is a date exposed filter attached, with granularity Y-m(year month). I want ...
4
votes
2
answers
4k
views
How to trigger a form and pass variables to $form_state with jQuery?
What is the way to trigger a Drupal form via JavaScript, and pass new values to $form_state while doing so?
I have a main form, which has an element that triggers a jQuery UI dialog with a form in it. ...
4
votes
1
answer
396
views
Append Fields to node form by ajax call
I have a node form with some fields, now I want to append some more fields to it on an ajax callback. in the ajax page I have rendered the new form elements with drupal_render function
My problem is ...
3
votes
0
answers
39
views
Can I access more information (user inputs) using delta index?
I am working on an edit form of a content type, which contains several related inline_entity_form, let's say ief1 and ief2. When I fill and submit ief1 and come to ief2, I need to access the input on ...
3
votes
0
answers
237
views
Apply constraint conditionally
I've just started to use Drupal 8's Entity Validation API and I'm applying constraints to entities in the following way using hook_entity_bundle_field_info_alter:
...
3
votes
0
answers
996
views
Drupal Ajax pager
Am looking for a solution to implement $form['pager'] = ['#type' => 'pager']; into AJAX callback (without reloading the page). I have read alot of posts concluding there is no a drupal way to do this ...
3
votes
2
answers
777
views
Form submission in modal is throwing an error
I have a Form which on submit calls another form via ajax and embeds it into a modal popup (Drupal8 standard) and when I click on submit of that modal form , I get a Drupal ajax error (I think it's ...
3
votes
0
answers
2k
views
How to make modal dialog submit buttons work when called with OpenModalDialog()?
I'm having an issue with some modal dialogs in Drupal 8.3.5. My requirement says that when I'm on a particular form under a particular condition, then a modal dialog pops up and collects some ...
3
votes
1
answer
235
views
How to render a @FormElement in Views area plugin
I am doing a custom plugin area for displaying some data in a views footer (Drupal 8).
I do something about just like this : Create a custom area plugin
The only point is, instead of #markup in the ...
3
votes
0
answers
1k
views
Render form widget inside a custom form
I'm trying to use the Image Widget Crop inside a form API. I followed the example module but there's no explanation how to do it after a file is uploaded.
My form is set like the code below. It works ...
3
votes
1
answer
2k
views
Entity Browser in Forms API
I'm having trouble getting the entity browser widget to work correctly in a custom form. Just wondering if anyone has had any success in getting it working. I've got to the point the button is ...
3
votes
0
answers
346
views
Image upload replaced modal
I have a form that has text_format form element with CKEditor in it and it has the image button in toolbar.
This form is being displayed via modal. When I click on the image the image upload/...
3
votes
0
answers
558
views
Multistep user profile form
How can I have a multistep user profile form in Drupal 8?
Using Profile module I can have the tabs for the different sections of the profile, but what I need to have is a single form with steps for ...
3
votes
1
answer
337
views
What to return from form AJAX Callback
I used the examples found here as my AJAX guide.
I have a custom form field
$form['elements']['refunded']
which is entirely defined in a single line as an array. My AJAX DIV's and callbacks work ...
3
votes
1
answer
518
views
hook_form_FORM_ID_alter being called twice (even before submit)
I want to make some changes to the "Content" page.
The ID of the form is views_form_content_page_1, so I made a quick test (after drush cr of course):
function ...
3
votes
0
answers
127
views
drupal_process_states function doesn't work for managed_file
The following code is working for text field, but it's not working for image field.
function THEMENAME_form_system_theme_settings_alter(&$form, FormStateInterface &$form_state, $form_id = ...
3
votes
0
answers
265
views
How to remove form validation in D8 under certain conditions?
I'm trying to save a node as a draft, but only if we are saving as a draft (Workbench Moderation). Otherwise, validation should be run as normal.
The user must be allowed to save a node in any state,...
3
votes
0
answers
681
views
Error saving custom field type module with "managed_file"
I have created a custom field type module (field plugin) containing four fields: title, description, address, image.
Drupal version: 8.02
This is the schema structure inside FieldType php file:
...
3
votes
3
answers
2k
views
Dynamically add input field using #ajax
As the question says, im not clear on how to go about adding new input fields depending on values of certain fields in the form.
I got as far as setting a callback and a wrapper, but i just can't ...
3
votes
2
answers
6k
views
Add a link field to block form
I've created a module with a custom block that extends BlockBase. To the block form I added multiple textfields and select boxes, by simply specifying the formatter in the '#type' configuration.
My ...
3
votes
1
answer
543
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
1
answer
154
views
Redirecting doesn't work with a custom form in a block
I developed a custom form with FAPI and added a block for it.
Block is included only on one specific page (basic node).
When user submits this form it should redirect user to external site (URL is a ...
3
votes
0
answers
847
views
Unzip a file in Drupal 7 Form API and upload extracted files
I'm creating a custom form using Drupal 7 Form API, and I need my users to be able to select a ZIP file containing a number of other files. I'd like to be able to extract the files and then upload ...
3
votes
1
answer
35
views
How can we use form directly without using drupal form handler
I want to post a html form into block as content and wanted to submit the form to a page.
where I will need to get the form values using $_POST and do some process on it.
How can i do that without ...
3
votes
0
answers
324
views
How can I return data from ctools modal to parent form
Let's say I have a Drupal form with a "Open popup" button and a text field. If user clicks on the button, I'd like to open ctools modal popup with two buttons (#3 and #4). Clicking on any button in ...
3
votes
1
answer
47
views
User Edit Page for different elements
I want to customize the user edit page. I want to separate the elements (eg. user password, user picture, user email) and put them each on a separate edit page. I tried the panels module, but that ...
3
votes
0
answers
116
views
Drupal 7 Webforms 4, prevent submission if value of field is less than or equal to previous submission
I know that you can prevent submission if a specific value has previously submitted.
However can you prevent a submission if the submission is less than or equal to a previously submitted value.
...
3
votes
0
answers
144
views
drupal_add_tabledrag dragging but not dropping
I am trying to use the drupal_add_tabledrag in a form table, the dragging is added fine, but dropping is not working
$entity_ids = range(10,20); // Loading dummy data
$entities = entity_load(...
3
votes
0
answers
638
views
Webform: change the way each component is displayed?
What I'm trying to achieve: I want to show my webform so each input would be displayed on separate page (kind of wizard or form with steps). I know that usually this is done by adding page breaks at ...
3
votes
0
answers
190
views
Disable form altering for admin pages on Bootstrap 3
My default theme is Bootstrap but I use Shiny theme as admin theme. Bootstrap theme alters the forms and fields.
And I use Hierarchical Select module, there is a dropbox for multiselection and the ...
3
votes
0
answers
584
views
Passing a default value to a custom form element
I have created a custom element through a module. This custom element is a drop down element which reads the values from an array saved in the variable table, which in turn is controlled by a ...
3
votes
0
answers
2k
views
Multiple date picker for date popup widget
I've been searching for a while, but didn't find any contribute module to store multiple date values picking them from only one date popup calendar widget, just a 2009 feature request for D6.
In D7 I ...
3
votes
1
answer
283
views
How to avoid the following errors while adding options for Polls in our site?
We use core drupal's Poll module where admin can add options to the polls by clicking "Add option" & at the same time they can remove the options by clicking "Remove option"
...
3
votes
1
answer
514
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 ...
3
votes
2
answers
3k
views
Implementing custom entity forms
In Making use of the admin UI, Step 3 - Implement the entity adding/editing form, it says that you need to implement "a" form with the ENTITY_TYPE_form() signature for add/edit/clone operations...
...
3
votes
0
answers
266
views
In tabledrag form, how to prevent certain elements from having children?
I want to use tabledrag to manage 2 kinds of elements. Let's call them branches and leaves. Branch can be parent to both branches and leaves. Leaf cannot be parent to anything. A support for class ...
3
votes
3
answers
3k
views
How to build multivalue form elements using Form API
With the 'field collections' module at the form level, you can create a fieldset (or 'field group') that will accept multiple sets of values.
Is there a way to do this with the Form API directly (or ...
3
votes
1
answer
456
views
Custom form values in hook_form_alter() not available in custom validate function
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, &$...
3
votes
4
answers
67
views
Is there a way to insert a view in a node form?
I have created a content-type based form (contact form) for anonymous users.
One of the fields in the form must displays a view.
This view is a slideshow view that displays different persons (site ...
3
votes
2
answers
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(
'...
3
votes
1
answer
440
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/...