1

I need to know how to get a +-delimited string to be appended to the end of the URL path without the + character being URL encoded.

Why: I'm trying to pass arguments to a View. I'm working on a custom module to conditionally route webform confirmations to a View. The view will take multiple arguments, returning all nodes matching the arguments (currently trying to do this with Views 3.0).

I've done proof-of-concept tests on the view that demonstrate that for a view with a path of, say, cbos/name1+name2 it will produce the desired result (i.e., displays nodes name1 and name2). So I know that this can be done from the Views side. (I'm pretty certain at this point Views has nothing to do with it, I just need to make clear why I need to do this.)

The problem is on the custom module / webform side.

I'm creating the URL path using the following code:

while ($cbo_short_name = db_fetch_array($result)) {
if ($count > 0) $delim = '+';
$cbo_short_names_arg .= $delim.$cbo_short_name['cbo_short_name'];
$count = $count + 1;
}
$redirecturl = "cbos/".$cbo_short_names_arg;
$node->webform['confirmation'] = drupal_urlencode($redirecturl); // ... have also tried setting this via the form settings page using tokens

... where $cbo_short_name is an array of short names (usually initials) for organizations. (There's usually only 1, but in about 15% of cases there will be 2 or 3 short names. The visitor has to be shown all of them. Hence, the View)

What this should do is produce a URL path of the form given above; what's happening is that '+' is getting URL encoded as %2B (e.g. cbos/name1%2Bname2), which breaks the Views argument string -- only the first result is returned.

If I could somehow force '+' to be passed intact, without URL encoding, this would work. But I'm at a loss for how to do that.

What I've tried so far:

  • Setting the confirmation URL on the form settings page (preferred, since I don't have to hard code it).
  • Setting the redirect URL programmatically (what you see above).

Both work to set a value, but in both cases the delimiters are URL encoded in the resulting URL path.

0

I am sure I am missing a or the point here, but, could you do something like this:

while ($cbo_short_name = db_fetch_array($result)) {
  if ($count > 0) $delim = '+';
  $cbo_short_names_arg .= $delim . drupal_urlencode($cbo_short_name['cbo_short_name']);
}
$redirecturl = 'cbos/' . $cbo_short_names_arg;
$node->webform['confirmation'] = $redirecturl;

eg, sanitize your arguments but then glue them together with the + (that isn't encoded) ?

| improve this answer | |
0

I don't think there is any build in Drupal helper function to do so, there is drupal_http_build_query to build query but it support only &as separator.

I think you should get your hand dirty a little bit and implement something for your use case take a look at this discussion about how to prevent drupal_goto from encoding plus and comma characters?
for your use case there is this suggestion and also this suggestion.

But first try with something like, add a function in your module like :

function custom_drupal_encode_path($path) {
  return str_replace(['%2F', '%2B'], ['/', '+'], rawurlencode($path));
}

and test with:

$node->webform['confirmation'] = custom_drupal_encode_path($redirecturl);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.