문제

I'm using Drupal's Forms API in my module, and I'm attempting to output a link as part of some markup:

//$output = l('Result', 'document/1234');
$output = '<a href="document/1234">Result</a>';

$form['results'] = array(
    '#type' => 'markup',
    '#markup' => $output,
)

I've tried use both a simple string and the l() function and in both cases when the page is rendered, the link does not work, and when I inspect the element, it is mangled like this:

<a href=" 1234"="" document="">

and the closing tag is missing.

So far as I can see I'm not doing any post-processing of any kind on the markup before it is rendered.

In other places in my module I have created links like this and they are output normally.

Any ideas?

도움이 되었습니까?

해결책

That's very strange, it sounds like another module must be changing it...do you have translation/string replacement modules installed by any chance?

This should help you get it around it in the mean time, you can use render arrays and theme_link to output a link like this:

$form['results'] = array(
  '#theme' => 'link',
  '#text' => 'Result',
  '#href' => 'document/1234',
  '#options' => array(
    'attributes' => array('class' => array('cool-class'), 'id' => 'cool-id'),
      //REQUIRED:
      'html' => FALSE,
  ),
);

Note that html in attributes is a required key.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top