Jump to content

Checkbox: other text in header than label text


Beate
 Share

Recommended Posts

Hello,
 
I'm using the API to generete a form. Is it possible to display sth other than the label name in the header (in my case "Newsletter") of a checkbox? This is my code:

$field = $modules->get("InputfieldCheckbox");
$field->label = "Ja, ich möchte per E-Mail über Neuheiten informiert werden.";
$field->attr('title','Newsletter');
$field->attr('id+name','newsletter');
$field->required = 0;
$form->append($field);

I tried title but it didn't work. I also looked in the source, but it seems it is not possible? I can't beleave that I'm the first one with this problem, but a search wasn't succesful :(

Thanks, beate

post-2091-0-96082500-1391694822_thumb.pn

Link to comment
Share on other sites

U  I often use

$field = $modules->get("InputfieldMarkup");
$field->value = "<label><input type='checkbox' name='newsletter'>Ja, ich möchte per E-Mail über Neuheiten informiert werden</label>";
$form->append($field);

Also you could use InputfieldCheckboxes and use addOptions(key, value) so you can set to not display header, but it will make the checkbox name an array

$field = $modules->get("InputfieldCheckboxes");
$field->skipLabel = Inputfield::skipLabelHeader;
$field->addOption("newsletter", "Ja, ich möchte per E-Mail über Neuheiten informiert werden");
$form->append($field);
  • Like 3
Link to comment
Share on other sites

If using the latest version of PW with the new default admin theme, it doesn't display the Inputfield label if there is no description – just shows the checkbox label. From the API side, you can also specify $field->label2 as something distinct from $field->label, where $field->label2 is the second label (the one for the checkbox). 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...