Drupal StackExchange

Form and gated content

3 days 2 hours ago

UPDATED from earlier:

I am using a simple Drupal form that collect user info before allowing the user access to donwloadable content. NOTE: This is using the form API and I am no longer using a modal; just using a regular page created by a hook. Here is the scenario:

<?php function my_form_menu() { $items = array(); $items['form/userinfo'] = array( //this creates a URL that will call this form 'title' => 'Download Form', //page title 'description' => 'A form that gathers user infomation', 'page callback' => 'drupal_get_form', //this is the function that will be called w hen the page is accessed. for a form, use drupal_get_form 'page arguments' => array('my_form'), //name of the form 'access callback' => TRUE ); return $items; } function my_form() { if (!empty($_COOKIE['Drupal_visitor_downloadbypass'])) { drupal_goto('this is where the pdf file will go'); // rest of the page will not execute because drupal_goto ends the request. } $form['name']['first'] = array( '#type' => 'textfield', '#title' => t('First name'), '#required' => TRUE, ); $form['name']['last'] = array( '#type' => 'textfield', '#title' => t('Last name'), '#required' => TRUE, ); $form['name']['title'] = array( '#type' => 'textfield', '#title' => t('title'), '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => 'Submit', ); return $form; } function my_form_submit($form, &$form_state) { // $form_state['values']['example'] contains the submitted value of 'example' element. user_cookie_save(array('downloadbypass' => 1)); $form_state['redirect'] = 'this is where the pdf file will go'; }

So here is my question: Now my form page is not showing up and I didnt change the hook except for the form name argument. The form will need to redirect back to the previous page and open the file in a new window upon submission.

Thanks!

phi

DataGuy

localhost subsites configuration

3 days 3 hours ago

I know how to install a single instance of Drupal very well but I want to create a number of sub-sites under my Drupal installation. My file structure is as follows:

drupal7_main -sites --drupal7_sub1 settings.php --drupal7_sub2 settings.php

I'm developing on my localhost and the plan is to duplicate the structure on the production server.

However, only drupal7_main works. When I visit localhost/drupal7_main, Drupal is ready and configurable as usual; when I visit localhost/drupal7_sub1, I get the following error.

Not Found
The requested URL /drupal7_sub1 was not found on this server.

I get the same for drupal7_sub2.

I'm trying to learn this process and would appreciate some help.

sisko

Ignore parts of the url or dynamically rewrite/alias the url

3 days 4 hours ago

I am having a problem and have been wrecking my brain over it...

I feel I might ohh how did I not think of that moment once I find the solution...

Basically, what I need to do is:

For any url containing a string like "abcmytrack" show the page/view/drupal url that is before it in url and ignore the rest. So if I go to node/1/abcmytrack/some/other/stuff/abc then just show node/1, if I go to nodeone/alias/page/abcmytrack/some/other then again just show nodeone/alias, but keep abcmytrack/some/other in the url.

What am I trying to do: there is some referral tracking that I am trying to implement in the form of.

/some/drupal/url/[trackid]/some/other/track/ids/even /any/drupal/url/[trackid]/any/even/number/of/arguments /[trackid]/some/other/set/of/arguments

basically for any url with [trackid] which is a string. It should just ignore anything starting with [trackid] and load the path before it as if [trackid] was not there.

The result is that they basically get converted to a cookie, but the site is behind varnish and akamai caching so on production the code does not run and cookie is not written. Best option at the moment is to use JS to write a cookie, but problem is that adding /[trackid]/some/other/set/of/arguments to some of the site urls like aliased node paths, homepage, etc. breaks the pages.

It might be possible to do it as url rewrites in .htaccess but this is a last resort. I would like to see if there are other options I am not considering.

I have attempted to do use hook_url_inbound_alter but it seems to do redirects and I loose the string from the url or otherwise it url encodes the string.

I have been wrecking my brain on this and cannot make this work. Granted I have some interesting requirements but it is one of those things that should be straightforward but it is not.

Boris Smirnov

Show/hide fields in a form based on the value of a checkbox

3 days 5 hours ago

Is there a way to hide a specific or specifics fields in Drupal when you create content until you checked a checkbox?

Now it looks like this:

I need something like this:

But I need some checkboxes to decide if I have a certain field to show or not. Like this:

(Fieldcollection item 'some information' is showing up now because I checked the checkbox before the label)

Is there a module for this?

What would be nice is if all fields only become mandatory if you checked a checkbox.

honline

How to disable redirection to the node after node form submission

3 days 6 hours ago

I have a node form exposed in the front-end to allow visitors to add their organisation to the list of partners. Below the form, I have exposed view block with the list of existing partners.

When a visitor enters a new organisation to the list I want the form just to add a new node type "partner" and reload the page/block without redirecting to the node content (node/[node ID]).

At the beginning I ed taxonomy terms instead and it worked as it should, now I want to achieve the same with node entity.

I have tried various solutions but none of it works correctly and I didn't find much by googling it.

For example, this is not functioning:

function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) { if ($form_id == 'node_partners_form') { $form_state->disableRedirect(); // This is not functioning } }

This does not work either:

function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) { if ($form_id == 'node_partners_form') { foreach (array_keys($form['actions']) as $action) { if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') { $form['actions'][$action]['#submit'][] = 'THEME_node_form_submit'; } } } } function THEME_node_form_submit($form, &$form_state) { $form_state->setRedirect(Url::fromUri('internal:/node/1')->toString()); } => Error: Route /partners does not exist.

Value of attribute action in the exposed node form is correct and therefore I think the proper solution should be elsewhere then altering form properties - probably it has more with the Drupal behaviour after adding a new node.

<form action="/en/partners">...</form>
Boštjan Biber

How to Logout user with Basic auth?

3 days 7 hours ago

I can log in, perfectly fine, but can't get logout to give me a JSON response. Currently, I can only do POST to

d8.com/user/logout?csrf_token=123&?_format=json

and that would log out, even though the token 123 is not the same as the given csrf-token at login or the logout token. This doesn't work without the token query, even though cookie/session isn't enabled anywhere

("message": "'csrf_token' URL query argument is missing.").

The logout happens when hitting a 403 forbidden on that URL.

Other info: csrf_token=123 is the actual query, doesn't need to be csrf-token or the log out token is given at login Version: 8.5.3 The only basic_auth turned ON, at all endpoints.

Sakox

How to fallback to default language when listing nodes in a view if no translation is available

3 days 8 hours ago

I have a list of projects, mostly in english, but some are translated in French.

When i visit the French version of my website, how can I list all projects that are translated in French and if no translation is available for a specific node, display the english counterpart.

Is that something possible in the view UI ? Or I'm guessing with a hook_query_alter.

Thanks,

Ebpo

Acquia Status

Acquia has detected a temporary interruption in Acquia Cloud interface services

3 days 2 hours ago

Apr 25, 15:52 UTC
Resolved - The underlying cause of this service interruption has been addressed. All services are currently operational. However, please note that the aggregated data for the affected time window has been lost and cannot be retrieved or backfilled.

Apr 25, 11:23 UTC
Monitoring - A fix for the cause of the interruption of service impacting some Acquia Cloud Stack Metrics has been deployed. We are currently monitoring the situation.

Apr 24, 19:07 UTC
Identified - The cause of the interruption of service impacting some Acquia Cloud Stack Metrics has been identified. We are currently working towards the fix and will provide additional information as it becomes available.

Apr 24, 13:28 UTC
Investigating - We are currently investigating an interruption in Acquia Cloud interface services impacting Acquia Cloud Stack Metrics to not report any Varnish data. We will provide additional information as it becomes available.

Drupal Planet

The Drop Times: DrupalCollab: How big is the Drupal Community?

3 days 5 hours ago
The Drop Times delves into the dynamics of the Drupal community with a detailed analysis of LinkedIn data, revealing the distribution and growth trends of Drupal professionals worldwide. This comprehensive study sheds light on regional concentrations and potential areas for community engagement.