Jump to content

Recommended Posts

Posted

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

Posted

There is a workaround, but it changes the value that is sent:

$field->checkedValue = 'Yes';

Displays 'yes' as label

  • Like 3
Posted

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
Posted

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

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
  • Recently Browsing   0 members

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