Drupal StackExchange

Dynamic select lists (dependent dropdowns)

3 hours 17 minutes ago

I created 2 dependent dropdowns in Drupal 7. In the first dropdown you need to choose the device, in order to see its attributes in the second dropdown.

When an option from the first list is selected, the Ajax throbber appears but it doesn't seem to be working and I don't get the appropriate options in the second dropdown.

I have read all examples and resources I could find online, but I haven't found how to fix this. Any help would be very much appreciated.

Below I attach the relevant code. Apologies in advance, I am new in Drupal.

function my_module_getdevicesfromrooms() { $dropdown1 = array(); $tabdelimited = file_get_contents("http://.../tabdelimited"); // some code return $dropdown1; } /** * The device name is required in order to get the attributes using this function */ function my_module_getattributesfromdevices($test) { $dropdown2 = array(); $tabdelimited = file_get_contents("http://...."); // some code return $dropdown2; } function my_module_form_ajax($form, &$form_state) { $form['#prefix'] = "<div id='latest-div'>"; $form['#suffix'] = "</div>"; $options_first = my_module_getdevicesfromrooms(); $value_dropdown_first = isset($form_state['values']['my_module_deviceurn']) ? $form_state['values']['my_module_deviceurn'] : $options_first; $state2 = my_module_getattributedfromdevices($value_dropdown_first); $form['my_module_deviceurn'] = array( '#type' => 'select', '#title' => 'Device', '#options' => $options_first, '#default_value' => $value_dropdown_first, ); $form['my_module_apply'] = array( '#type' => 'button', '#title' => t('Apply'), '#default_value' => t('apply'), '#ajax' => array( 'callback' => 'my_module_ajax_callback', 'wrapper' => 'nodes-div', 'method' => 'replace', 'effect' => 'fade', ), ); $form['my_module_attributes'] = array( '#type' => 'select', '#title' => t('Attributes'), '#options' => $state2, '#default_value' => variable_get('my_module_attributes', ''), ); return $form; } function my_module_ajax_callback($form, $form_state) { return $form; }
pouket

How to set visibility or hidden for the user registration form custom fields using hook function in drupal 9

3 hours 30 minutes ago

I am new to Drupal.

I have created new two custom fields via the admin panel in the user registration form.

For example, I want to show only the "DOB" field should be visible only on the front end and the "Phone number" field should be visible only on the admin end. How to handle the Field visibility programmatically using the hook's function?

Can anyone guide me on how to achieve this?

I have tried like below for the field should hide in the frontend but should be visible at the backend. Please refer to the code

Please refer here.

<?php use Drupal\Core\Access\AccessResult; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Field\FieldItemListInterface; /** * Implements hook_entity_field_access(). */ // function yourmodule_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { // } function custom_user_registration_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { $result = AccessResult::neutral(); if ($field_definition->getName() == 'field_dob') { if ($op == 'update' && !in_array('administator', $account->getRoles())) { $result = AccessResult::forbidden(); } } return $result->addCacheContexts(['user.role:administrator']); } ?>

Error:

Thanks in advance.

jaisa

How to set an email recipient in Webform?

3 hours 39 minutes ago

I need to list one recipient for a contact form I've created with Webform module.

I tried to look for this in /admin/structure/webform/manage/contact/settings but didn't find where to list a recipient or recipients for the form.

How to set an email receiver/recipient in Webform?

al-hadi

Fetch Link field Label and Link separately in views-view-fields template

4 hours 20 minutes ago

How can I fetch label and link field in views-view-fields--VIEW-NAME-HERE.html.twig file

So far I have tried

{{ fields.field_action_link.content }} give me the anchor tag prebuilt (html) {{ fields.field_action_link.0.url }} {{ content.field_action_link[0]['#url'] }}

but none of them seems to work for me. I am able to retrieve all other fields including image field.

June

Webform Select Element Optgroup / hierarchy

5 hours 24 minutes ago

Hello fellow Drupal users, I have created an advanced HTML element in my webform. When the form is submitted the advanced html element reverts back to the default setting, which in this case is option A1. The users selection and data for this element is not in the submission.

This is the YAML an example form:

processed_text: '#type': processed_text '#display_on': both '#text': | <select name="processed_textone" id="processed_textone" style="width: 570px;"> <optgroup label="A"> <option value="A1">A1</option> <option value="A2"> A2</option> <option value="A3"> A3</option> </optgroup> <optgroup label="B"> <option value="B1">B1</option> </optgroup> <optgroup label="C"> <option value="C1">C1</option> <option value="C2">C2</option> </optgroup> '#format': full_html

I would like to get the data of the selection upon submission. I tried using a computed twig and Ajax, but that doesn't seem to work either. I think I might be able to add a javascript file to get this data into the submission, but I'm not sure. I'm pretty new at subtheming and js in general.

michelle_wood

Your message has been sent. WITH Unable to send email. Contact the site administrator if the problem persists [closed]

6 hours 5 minutes ago

Drupal 9.4.6 with Webform module.

I have created a simple contact form but when sending it I get both messages:

  • Your message has been sent.
  • Unable to send email. Contact the site administrator if the problem persists.

No email reaches my Gmail account (me the admin of the website and the only registered user in the website).

As I host the website on shared hosting environment, I can't control any infrastructure.

How to try to solve that problem?

Examples to logs
Error sending email (from Dixisset <example@example.com> to admin@example.com with reply-to Dixisset <example@example.com>).
Error sending email (from =?utf-8?Q?=D7=91=D7=9F_=D7=90=D7=94=D7=A8=D7=95=D7=A0=D7=99?= - =?utf-8?Q?=D7=9E=D7=A7=D7=93=D7=9D_=D7=90=D7=AA=D7=A8=D7=99=D7=9D?= <admin@example.com> to admin@example.com with reply-to =?utf-8?Q?=D7=91=D7=9F_=D7=90=D7=94=D7=A8=D7=95=D7=A0=D7=99?= - =?utf-8?Q?=D7=9E=D7=A7=D7=93=D7=9D_=D7=90=D7=AA=D7=A8=D7=99=D7=9D?= <admin@example.com>).
al-hadi

Filter by two fields in a paragraph

7 hours 12 minutes ago

I’m trying to add an exposed filter to a content type, containing a paragraph than can have multiple entries. This paragraph contains two taxonomy fields with hierarchy. And I’ve got a view with exposed filters of a search API index, for users.

When a user searches on the views page, I want them to be able to filter that content type by both taxonomy fields within the paragraph.

As an example, for content type ‘cars’, with a paragraph contains two fields, “car part” and “color”, with multiples possible on one car - allowing me to add “seats” = “white”, and/or “exterior” = “blue”

Then, within the exposed filter, users should be able to filter for cars that have brown seats.

I’ve indexed both the paragraph’s fields and can filter on each of them, but the two filters are not aware of each other being matched in a paragraph field entry. Example: A user can currently filter for the car part "seats" and color “brown”, and they’d get cars with seats of any color and having any part that is brown.

I don't think changing the filters to 'and' works, because I'd just get the same result: cars with entries for seat, and for brown — but not in the same paragraph entry. where

I did try the “combine fields filter” module, I have no idea if it could work, because I got an error and had to uninstall it

Let me know if there’s anything more specific needed, and I’ll update the post.

turpentyne

Why is the login redirecting to the access denied page?

7 hours 13 minutes ago

This question has been asked before but I see only D7 versions of the question, and none of their answers have helped me in D8.

I log in perfectly fine with Chrome or Firefox, but IE 11 redirects to the /user/1 page (or /user/2, or whoever you are logging in as) and states 'Access Denied.' If you enter incorrect credentials it states "unrecognized user/pass," but if you enter correct ones it just does the redirect and nothing happens.

This is on a fresh install of D8 RC2 and what's worse is I can do a fresh install of D8 RC2 on a different server and IE 11 login works fine. It's something about my server that's causing this. I thought it might be cleanURLs but mod-rewrite is on for both servers.

D7 solutions seem to say, check settings.php and the cookie_domain or base_url variables, but those don't seem to be a part of Drupal 8.

I have cleared IE's cache/cookies about a thousand times.

RaisinBranCrunch

How do I add fields and hide them from client?

8 hours 15 minutes ago

I added fields to a Client profile using Profile2, such as first name and last name. But I added another fields, let's call it "Assigned Consultant".

But the "Assigned Consultant" field...

  • I don't want it to be available on registration
  • I don't want it to be available on the Client view user profile page
  • I don't want it to be available on the Client edit user profile page

I just want the "Assigned Consultant" field to be available to Administrator users.

How can I do that?

leonel

How do I set up CORS?

8 hours 17 minutes ago

Drupal 8 has RESTful web service in-built in core and since 8.2 we don't need cors module.

Now to use services we just enable and configure default.service.yml file as specified in here

However, I was not able to configure this setup to allow web service access over another domain.

My current service.yml setup for cors is:

cors.config: enabled: true # Specify allowed headers, like 'x-allowed-header'. allowedHeaders: ['x-csrf-token,authorization,content-type,accept,origin,x-requested-with'] # Specify allowed request methods, specify ['*'] to allow all possible ones. allowedMethods: ['POST, GET, OPTIONS, DELETE, PUT'] # Configure requests allowed from specific origins. allowedOrigins: ['*'] # Sets the Access-Control-Expose-Headers header. exposedHeaders: false # Sets the Access-Control-Max-Age header. maxAge: 1000 # Sets the Access-Control-Allow-Credentials header. supportsCredentials: false

I googled to find further detailed configuration on this but could not find one.

I am creating this for test development across two different domains.

Using pantheon dev environment for web services and localhost custom .dev domain for consuming those services.

Service access working fine using chrome CORS extension.

sarathkm