I'm trying to build this:
<a href="/en/webform?edit[submitted][nameofthepet_webform_fieldset][webform_nume_animal_comp]=NAME-OF-PET" class="btn btn-primary btn-xs">Adopt NAME-OF-PET</a>
the code I'm using:

$adopt_me_link_male = l(t("Adopt !name",
 array('!name' => $node->field_pet_name['und'][0]['safe_value']), array('context' => 'Male pet name')), 'node/163', array('query' => array('edit[submitted][nameofthepet_webform_fieldset][webform_nume_animal_comp]=' => $node->field_pet_name['und'][0]['safe_value'])), array('attributes' => array('class' => array('btn', 'btn-primary', 'btn-xs'),),) );

The above code generates the link but I have two problems:
1. the link looks like this:
<a href="/en/webform?edit%5Bsubmitted%5D%5Bnameofthepet_webform_fieldset%5D%5Bwebform_nume_animal_comp%5D%3D=NAME-OF-PET">Adopt NAME-OF-PET</a>

2. there's no css class applied to the anchor

Why the classes are not applied and the link looks so messy?

Thank you!

Comments

VM’s picture

The question is better suited to the 'Module development and code questions' forum. Please edit the opening post and move it. Thanks.

Jaypan’s picture

I think you want this:

$adopt_me_link_male = l(
  t(
    'Adopt !name',
    array('!name' => $node->field_pet_name['und'][0]['safe_value']),
    array('context' => 'Male pet name')
  ),
  'node/163',
  array(
    'query' => array(
      'edit' => array(
        'submitted' => array(
          'nameofthepet_webform_fieldset' => array(
            'webform_nume_animal_comp' => $node->field_pet_name[LANGUAGE_NONE][0]['safe_value']
          )
        )
      )
    ),
    'attributes' => array('class' => array('btn', 'btn-primary', 'btn-xs'))
  )
);

You had your attributes embedded in an unnecessary array. This is why it's often better to write out your long link codes as above, to make it easier to see what is happening.

gge’s picture

Thank you very much. That's exactly what I needed :)