403 Error on AJAX Request in add new item (collection field)

1 day 7 hours ago

I have normal content type which has 12 collection fields each field has unlimited value when i try to click add new item on any field it gives me ajax error

An AJAX HTTP error occurred. HTTP Result Code: 403 Debugging information follows. Path: /?q=system/ajax StatusText: Forbidden ResponseText:

I have another content type and also has collection field with unlimited value .. but it works without any problem so please help me why some content type has error and the other doesn't have

by the way: i use D7 and i upgraded it to 7.35 but this problem was before the upgrading

i have checked all the answers in the Drupal Answers but unfortunately did it help

edit:

ResponseText: @import url("http://example.org/modules/system/system.base.css?nlmla7"); @import url("http://example.org/modules/system/system.base-rtl.css?nlmla7"); @import url("http://example.org/modules/system/system.menus.css?nlmla7"); @import url("http://example.org/modules/system/system.menus-rtl.css?nlmla7"); @import url("http://example.org/modules/system/system.messages.css?nlmla7"); @import url("http://example.org/modules/system/system.messages-rtl.css?nlmla7"); @import url("http://example.org/modules/system/system.theme.css?nlmla7"); @import url("http://example.org/modules/system/system.theme-rtl.css?nlmla7"); @import url("http://example.org/sites/all/modules/date/date_api/date.css?nlmla7"); @import url("http://example.org/sites/all/modules/date/date_api/date-rtl.css?nlmla7"); @import url("http://example.org/sites/all/modules/date/date_popup/themes/datepicker.1.7.css?nlmla7"); @import url("http://example.org/sites/all/modules/date/date_repeat_field/date_repeat_field.css?nlmla7"); @import url("http://example.org/modules/field/theme/field.css?nlmla7"); @import url("http://example.org/modules/field/theme/field-rtl.css?nlmla7"); @import url("http://example.org/sites/all/modules/field_hidden/field_hidden.css?nlmla7"); @import url("http://example.org/modules/node/node.css?nlmla7"); @import url("http://example.org/sites/all/modules/recieve_orders/css/orders_styles.css?nlmla7"); @import url("http://example.org/modules/search/search.css?nlmla7"); @import url("http://example.org/modules/search/search-rtl.css?nlmla7"); @import url("http://example.org/modules/user/user.css?nlmla7"); @import url("http://example.org/modules/user/user-rtl.css?nlmla7"); @import url("http://example.org/sites/all/modules/views/css/views.css?nlmla7"); @import url("http://example.org/sites/all/modules/views/css/views-rtl.css?nlmla7"); @import url("http://example.org/sites/all/modules/admin_menu/admin_menu.css?nlmla7"); @import url("http://example.org/sites/all/modules/admin_menu/admin_menu-rtl.css?nlmla7"); @import url("http://example.org/sites/all/modules/admin_menu/admin_menu.uid1.css?nlmla7"); @import url("http://example.org/sites/all/modules/ctools/css/ctools.css?nlmla7"); @import url("http://example.org/sites/all/modules/adminimal_admin_menu/adminimal_admin_menu.css?nlmla7"); @import url("http://example.org/modules/shortcut/shortcut.css?nlmla7"); @import url("http://example.org/modules/shortcut/shortcut-rtl.css?nlmla7"); @import url("http://example.org/sites/all/themes/adminimal_theme/css/reset.css?nlmla7"); @import url("http://example.org/sites/all/themes/adminimal_theme/css/style.css?nlmla7"); @import url("http://example.org/sites/all/themes/adminimal_theme/css/style-rtl.css?nlmla7"); @import url("http://example.org/sites/all/themes/adminimal_theme/css/mobile.css?nlmla7"); @import url("http://example.org/sites/all/themes/adminimal_theme/css/tablet.css?nlmla7");ySite.org/sites/all/themes/adminimal_theme/css/tablet.css?nlmla7");

and there are too many custom modules in my site

but the thing which make me more conflicted is why it doesn't give error in the other content type

Mohammad Alabed

Getting site-offline message when trying to drupal_bootstrap from command line

1 day 10 hours ago

I'm trying to bootstrap drupal from a standalone PHP script at the command line from sites/all/modules/mymodule/mymodule.php.

<?php chdir('/sandbox/mysite/'); require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

I'm attempting to run it from the command line, but I get Drupal site-offline when I do (trimmed for brevity):

cd /sandbox/mysite php sites/all/modules/mymodule/mymodule.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Site off-line | Pressflow</title>

The site is online and works fine from the browser. DRUPAL_BOOTSTRAP_DATABASE is where this fails, since I can bootstrap the DRUPAL_BOOTSTRAP_CONFIGURATION and DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE phases without a problem. Anyone run into this before? Thanks in advance.

Vincent

Autofill texfields based on select option in dynamic fieldset

1 day 10 hours ago

In my custom form i am dynamically generating multiple fieldsets.Each field set has select option(dropdownlist) and textfield generated dynamically. The value for textfield is dynamically generated based on user selected value from select option.

My problem is that if i select species from fieldset2 then density texfield1 in fieldset1 is overwritten and density textfield2 in fieldset2 is empty which is wrong. Each time the ajax callback return value is overwriting textfield1 in fieldset1(Field#1)

function fuel_design_tool($form, &$form_state) { $form = array(); $form['#tree'] = TRUE; if (empty($form_state[FIELDS_NUM])) { $form_state[FIELDS_NUM] = 1; } for ($i = 1; $i <= $form_state[FIELDS_NUM]; $i++) { $form['field'][$i] = array( '#type' => 'fieldset', '#title' => t('Field #@num', array('@num' => $i)), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['field'][$i][FORM_FIELD_SPECIES] = array( '#type' => 'select', '#required' => TRUE, '#title' => 'Choose Species', '#options' => _load_species1(), '#default_value' => 0, '#ajax' => array( 'callback' => 'fuel_design_tool_callback', 'wrapper' => 'fuel_design_tool-wrapper', 'event' => 'change', ) ); $profile = isset($form_state['values']['field'][$i]['FORM_FIELD_SPECIES']) ? ($form_state['values']['field'][$i]['FORM_FIELD_SPECIES']) : NULL; $form['field'][$i][FORM_FIELD_DENSITY] = array( '#type' => 'textfield', '#prefix' => '<div id="fuel_design_tool-wrapper">', '#suffix' => '</div>', '#title' => t('Density'), '#value' =>$profile, ); $form['add_field'] = array( '#type' => 'submit', '#value' => t('Add More fieldet'), '#submit' => array('fuel_design_tool_add_name') ), $form['submit_button'] = array( '#type' => 'submit', '#value' => t('Submit'), "#submit" => array("fuel_design_tool_submit"), ); return $form; } function fuel_design_tool_add_name($form, &$form_state) { $form_state[FIELDS_NUM]++; $form_state['rebuild'] = TRUE; } function fuel_design_tool_callback($form, &$form_state) { for ($i = 1; $i <= $form_state[FIELDS_NUM]; $i++) { $form['values']['field'][$i]['FORM_FIELD_DENSITY'] = $form_state['values']['field'][$i]['FORM_FIELD_SPECIES']; return array ( $form['field'][$i]['FORM_FIELD_DENSITY'], ); } } }

My callback function returns only one value and that by default filled to fiedset#1 textfield.I guess i need to modify my callback function.

I am looking forward for your kind help.

If my question is not clear please let me know. I am finding bit difficult to explain this problem

Naveena

Quiz - Undefined array key 1 in Drupal\quiz\Controller\QuizQuestionController

1 day 11 hours ago

Hello and thank you for helping me! I'm new to Drupal, working on someone else's site.

Background:

  • The site was successfully migrated from Drupal 7 to 9.5.9.

  • Quiz 6.0.0-alpha7 is installed.

  • Multiple choice and true/false answers modules are installed.

  • All the other quizzes are working.

  • The previous dev added a quiz and its questions. It was working for awhile, I believe. It has had users who took it, which limits how much I can change it.

  • I was asked to edit the text in the question and answers. I created a new revision for this, hoping it would solve my inability to take the quiz. I only changed text. No settings.

  • I cannot take the quiz either through the button on the course or through the admin Quiz edit section. Both give me the same error. When I try to take the quiz, I get the following error:

    Warning: Undefined array key 1 in Drupal\quiz\Controller\QuizQuestionController->numberToQuestionResultAnswer() (line 266 of modules/contrib/quiz/src/Controller/QuizQuestionController.php).

Also, it tells me I am not authorized to view the page and that I should log in. I am logged in with admin privileges.

Failed Attempts to Fix it:

  • I changed the custom URL in an effort to fix the problem and double-checked that the course page was calling the right quiz.
  • I've compared the settings on working quizzes to those on the non-working one and they are the same.
  • I checked the permissions settings and I'm set to admin and superadmin.

I've been trying to figure this out for days! I'm getting desperate. If anyone can help me, I'd be ever so grateful!!

Thank you, Angel...

Angel Leigh McCoy

Add custom operator for condition() in search_api

1 day 11 hours ago

I am trying to implement hook_search_api_multi_query_alter but it seems 'IN' operator does not work here. I have to check condition on array. Any pointers for start building custom operator.

function my_module_search_api_multi_query_alter(SearchApiMultiQueryInterface $query) { $indexes = $query->getIndexes(); dpm($query->getFields()); if (isset($indexes['solr_content_index_dev'])) { $query->condition('solr_content_index_dev:nid', array(2918, 2367), 'IN'); } }
arpitr

Load an AJAX submission enabled webform using another AJAX call

1 day 14 hours ago

I am using Javascript/AJAX to call a path defined in a custom module which loads existing node content for display. i.e. you are at:

/custom/path

and it makes an AJAX request to /custom/content with arguments to load the content for the page (placed in #main-content). Content may be a page, video or other custom Content Types.

Custom navigation elements on the page cause further AJAX requests to /custom/content with different arguments to replace the content.

This has worked well until the need to incorporate webform's into the mix. Due to the non-refreshing nature of the page the webform needs to be loaded, displayed and submitted using AJAX.

I have setup hook_form_alter to add the necessary $form['actions']['submit']['#ajax'] to webforms and they work properly when called directly. The form submits via AJAX. However, when they are loaded via AJAX this does not work. They submit as per normal and navigate away from my desired wrapper page.

I have ensured Drupal.attachBehaviours is being called post AJAX load. I suspect my problem is in the loading/rendering of the webform in the module, but have not been able to successfully piece it together. The module serving /custom/content basically does the following:

$node = node_load($node_id); $output = drupal_render(node_view($task, 'full', NULL)); echo $output;

It displays the webform perfectly (like other content) - it just doesn't implement the #ajax submission part. I've tried all manner of more specific form buulding for when $node-type = webform but no success.

Mike

Create node by post Api call fail with message "Could not determine entity type bundle: \\u0022type\\u0022 field is missing."}

1 day 14 hours ago

I'm trying to create a node via Drupal API but I get this error:

Got error 'PHP message: PHP Fatal error: Uncaught GuzzleHttp\\Exception\\ClientException: Client error: `POST https://site.it/entity/node?_format=hal_json` resulted in a `422 Unprocessable Entity` response:\n{"message":"Could not determine entity type bundle: \\u0022type\\u0022 field is missing."}

This is my function:

public function createFaq($notes, $telegram_id){ $url = "/entity/node?_format=hal_json"; $opt = [ 'headers' => self::$baseHeader, 'body' => json_encode([ [ 'type' => [ ['target_id' => 'faq'] ], 'title' => 'title', 'utente' => [ [ 'target_id' => '123462' ] ], 'field_domanda' => [ [ 'value' => $notes['domanda'] ] ], 'field_presenza' => [ [ 'value' => $notes['presenza'] == "Si"? true : false ] ], ] ]) ]; $response = $this->client->request('POST', $url , $opt); $r = json_decode( $response->getBody()); return $r; }

But it's really strange, because this other function is working:

public static function createUser($title){ $url= "/entity/node?_format=hal_json"; $opt = [ 'headers' => self::$baseHeader, 'body' => json_encode([ 'title' => [ [ 'value' => $title ] ], 'type' => [ [ 'target_id' => 'article' ] ], ]) ]; $response = $this->client->request('POST', $url , $opt); $r = json_decode( $response->getBody()); return $r; }

Can someone understood my error?

Shyghar

How to get a drupal path in a modal form?

1 day 16 hours ago

I would like to have a specific path in a modal form. I tried several things but cannot get i work.

Modal_form

I installed the module, clear cached and added into a body tekst the example of the module:

<a class="ctools-use-modal ctools-modal-modal-popup-large" href="node/2">Link to click</a>

When I click on this link I will get ajax error 200.

Colorbox and Colorbox Node

Maybe it is working with this module...installed module. After installation I Enabled the Colorbox load option and clear cache.Put the below link in a body text.

<p><a class="colorbox-load" href="node/2?width=500& height=500">colorbox test</a></p>

After clicking the link I will see node/2 in the browser but not in a modal form. The filters in the editor is full html

Ctools automodal module

Installed the module. Put node/2 into the extra modal links box. Pushed the submit button but it is not saved

So probable I do something not good but what? Any suggestion? Using chrome.

Console errors: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/ with jquery

Any investigation says that this is a ajax call but I'n not sure.

set jquery update to 1.9 for front end. But no luck :-(

Any suggestion?

Justme

I can't set page in drupal as unpublish

1 day 18 hours ago

I have issue I can't solve it and I don't know the reason of it

I already have page in drupal have status published and when I change status to draft still page not change status to draft it's seen published

how can I solve this problem and thanks :)

Ahmed Essam

How to add destination parameter in hook url_inbound_alter

1 day 18 hours ago

Hi I have used hook_url_inbound_alter to alter the URL. When I access user/%/order anonymously it should redirect ti user/login. I have used below code

function module_url_inbound_alter(&$path, $original_path, $path_language) { $argument = explode('/', $path); if (!user_is_logged_in() && isset($argument[0]) && $argument[0] == 'user' && isset($argument[2]) && $argument[2] == 'orders') { $path = 'user/login'; } }

It redirects the user to login page but my question is how to add destination parameter. Above code redirects localhost/drupal/user/login but I want to add destination paramater such as localhost/drupal/user/login?destination=user/1/order

When I tried to add the desination variable in $path variable

$path = '/user/login?destination=user/1/order;

I am getting the url like this

http://localhost/drupal/user/login%3Fdestination%3Duser/1/order

Instead it should be like this.

http://dt.drop/user/login?destination=user/1/order

How can I achieve this.

Vamsi

How to check if managed_file has uploaded a video and use it in states

1 day 19 hours ago

I want to disable the submit button in a form for as long as there are no value/uploaded video in a managed_file but I can't seem to find what form name or element property I have to check for in #states.

I have the following:

$form['file'] = [ '#type' => 'managed_file', '#title' => t('File'), '#description' => $this->t('Choose video to upload.'), '#upload_validators' => $validators, ]; $form["submit"] = [ "#type" => "submit", "#value" => t('Submit'), '#states' => [ 'enabled' => [ ':input[name="file"]' => ['empty' => FALSE], ], ], ];

I've also tried using value => true, :input[name="files[0] and :input[name="files[file] without luck. How can I enable the submit button when file has been processed?

NicklasF

Drupal prevents file save on chunked upload because of php.ini max upload size

1 day 21 hours ago

I'm encountering a tricky problem with my custom file widget (which extends the core file widget). It chunks files so that I don't have to raise upload_max_filesize and post_max_size in php.ini, and puts them together. The problem is, even though the files now exist remotely (and have also been saved as file entities in Drupal) it refuses to save them into the field, because even though the file field's settings are set to 500 MB, php.ini's uploads are maxed at 20 MB.

The problem is in FileItem.php:

public function getUploadValidators() { $validators = array(); $settings = $this->getSettings(); // Cap the upload size according to the PHP limit. $max_filesize = Bytes::toInt(file_upload_max_size()); if (!empty($settings['max_filesize'])) { $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize'])); } // There is always a file size limit due to the PHP server limit. $validators['file_validate_size'] = array($max_filesize); // Add the extension check if necessary. if (!empty($settings['file_extensions'])) { $validators['file_validate_extensions'] = array($settings['file_extensions']); } return $validators; }

Which calls file_validate_size in file.module. I've already tried using ini_set() to change the file size ini values, but that doesn't seem to work.

So, to recap:

Drupal has the file

My widget tells it to save the file by its fileID for the file field

Drupal tells me it won't save the file that it already has because of php file upload limits

Can anyone think of something I can do to get around this without modifying core?

RaisinBranCrunch

How to keep preview page active but not displayed in the progress line

1 day 21 hours ago

In my form settings (/admin/structure/webform/manage/testing/settings/form) I have:

Form preview settings > Enable preview page > Optional

to be able to display the preview page, which I can access from the last step on the form by clicking the "preview" button.

The preview page is also contemplated on the "progress line" as an additional step, and this is what I need to avoid.

I mean, right now, if the form has 6 steps, it shows 7 on the progress line because of the preview page, if I disable the preview page, the step disappears, but the preview page is no longer available...

Any ideas? thanks!!

Andrés Chandía

hiding taxonomy terms on term page

1 day 22 hours ago

I'm struggling theming the taxonomy-term page and since i'm not really getting anywhere, i now embedded two blocks (created with views) in my taxonomy-term.tpl.php. Now, that views is showing everything the way I want it, I don't want the term page itself output its data. That's why I'm trying codes like

<?php hide($content); ?>

But that won't do the trick. How can I just show the Blocks from Views instead of the content taxonomy provides itself?

Thanks!

user3027413

Redisplay Captcha on form error in Ajax form submit

1 day 23 hours ago

I have a Fancybox form and the form is sent via Ajax. I know that there is the error about "reuse attack" for Captcha, but this is not my case.

When I wrong the form (some required fields missing) I see the fieldset of Captcha, but no Captcha inside. It's empty.

How can I fix this ?

ZioBudda

How do I add a CSS class to a form label?

1 day 23 hours ago

I want to add a CSS class to a label on a page that is using Drupal 8 Form API. I have been unable to find a reference online on how to apply that. I have used the following workaround, but it produces some strange results.

public function buildForm(array $form, FormStateInterface $form_state) { $form['label1'] = array( '#type' => 'label', '#title' => $this->t('QUESTIONNAIRE'), '#id' => 'lbl1', '#prefix' => '<div class="caption1">', '#suffix' => '</div>', ) ;

and the HTML rendered is:

<div class="caption1"><label for="lbl1" class="control-label"> <div class="caption1"></div>QUESTIONNAIRE </label>

Not only is the div statement in the wrong place but it is rendered twice.

I had found postings from several years ago that show this was not possible, but I am hoping that since then, and with D8, it has been fixed. I do not want to do it with prefix/suffix, but as a separate array element.

PS: this site is Drupal 8.0.0-rc2

Steve D.

Add CSS class to view image_field in twig

2 days ago

In my custom view fields twig file views-view-fields--search--product_result.html.twig I try to theme my view item.

{{ fields.field_images.content }} <h5 class="card-title">{{ fields.title.content }}</h5>

How do I add a CSS class to my image field {{ fields.field_images.content }}?

meez

Webform entity select submission displaying different result than element

2 days ago

I have a webform in Drupal 8 with an entity select element. The element is populated from an entity reference view. I have a book content type with information about the book such as title and author. I also have a field collection in book containing more specific details such as ISBN and format. The entity reference view displays title-isbn-format. For example:

Dune - 9780441013593 - Paperback

Dune - 9780143111580 - Hardcover

I applied the view entity reference patch posted here. The form correctly displays the output of the view. How do I get the same display in the form submission? If I set the form display to value and select Dune paperback the result is "MyBookFieldCollection 0 of Dune (9)."

I tried using tokens but I can only get the field collection info, not the book info.

Here is the source for the element:

book_title: '#type': entity_select '#title': 'Book Title' '#select2': true '#format': custom '#format_html': '[webform_submission:values:book_title:node:title] - [webform_submission:values:book_title:entity:field_isbn_13] - [webform_submission:values:book_title:entity:field_format]' '#format_text': '[webform_submission:values:book_title:node:title] - [webform_submission:values:book_title:entity:field_isbn_13] - [webform_submission:values:book_title:entity:field_format]' '#target_type': field_collection_item '#selection_handler': views '#selection_settings': view: view_name: entity_reference_for_form display_name: entity_reference_1 arguments: { }

This correctly displays the ISBN and book format but not the book title.

MikeZ
Checked
17 hours 57 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed