Can PloneFormGen's mailer adapter include hidden / server-side-only fields? - plone

I'm using PloneFormGen's mailer adapter and noticed it omits hidden or server-side-only fields from the e-mail. How do I save those fields?

Server-side-only fields are excluded from the mailer's body template by this code: https://github.com/smcmahon/Products.PloneFormGen/blob/master/Products/PloneFormGen/content/formMailerAdapter.py#L725
One way to include those values in the e-mail is to include them in the mailer template as <div tal:content="python:request.form.get('field-name')">field value</div>. If you only need those values in the mailer then it might be just as practical to produce them in the template without going through the form.

Related

Symfony forms ChoiceType how to add new choices from user's input

I am using js library that allows user to add new values into html select element but I cannot find a way handing that new values from symfony side and dynamically add new option.
As one of the solutions I was trying to use 'choice_loader' options with default ChoiceType field and implementing ChoiceLoaderInterface like in this post but there should be a simpler way.
I don't think you can do it in an other way with a ChoiceType but maybe you can create you own custom type :
You can create your select element by customize your form rendering or/and default classes set in your custom FormType.
You can use a ModelTransformer in order to retrieve your existing values and create new ones
You can use a simple TextType in inheritance format the data send by the form with a delimiter and create a ViewTransformer in order to retrieve a collection on the other side

Augment SilverStripe UploadField

I'd like the augment the HTML that gets appended to the Upload field on a file upload and add but I can't seem to find where the where the div.ss-uploadfield-item-info is added.
Specifically I'd like to add a second hidden input after the file ID field.
You need to overwrite the template for the uploadfield, the original is in /framework/templates/UploadField.ss. Using ->setTemplate('YourTemplate') you can even set the template for one single instance of the UploadField.
The hidden field can either be set statically in your own template or using HiddenField.

How to show wordpress setting api validation error message?

I have created a setting api for my new plugin. It has four <input> field and one <select> option. In that field , user can change value according to their requirement. But it must be valid value. Suppose , one <input> field support only integer value. so when user will fill that <input> field by string or by other things, it will show an error message. Please tell me how can i do that? Can you suggest any tutorial ?
When using add_setting you can pass a sanitize_callback option as part of the array, this can contain the name of a function that is run which can contain your validation.
A similar method exists for JavaScript too, which you could use to validate the fields as well.
You asked for a tutorial too, here is one that outlines the method I've described: http://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/

Is schema definition available in form widgets for formType generated in symfony 2?

When a form type corresponds to a model, I see in the form view, it renders "required" class for notnull table field types' label. I was wondering if it in any way uses schema definition? How is it passed?
Like in form_label.html.php, we have
<?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?>
How is $required available in here?
See the Field Type Options Guessing section of the the Forms chapter of the Symfony book.
required: The required option can be guessed based on the validation rules (i.e. is the field NotBlank or NotNull) or the Doctrine metadata (i.e. is the field nullable). This is very useful, as your client-side validation will automatically match your validation rules.
As far as I know (Symfony 2.0.x), required FormType option does only enable HTML5 client-side validation on the field. It has nothing to do with server-side validation, and less with database schema.
required option is set to true by default. So you have to explicitely set it to false to disable HTML5 validation and required class on the HTML input.

Is it possible for a behavior to specify a custom subform for fields which it adds

I'm trying to create a behavior which adds 2 new fields to content types to which it is applied, but I'd like those fields to have a custom subform on the add/edit forms for content types it is added to. Is there any straightforward way to do this as part of the behavior?
You can use a fieldset inside your schema
from plone.directives import form
....
class IMyBehaviorSchema(form.Schema):
form.fieldset('myfieldset', label=u"My Behavior fieldset",
fields=['firstfieldname', 'secondfieldname'])
to display your additional fields with Plone form tabbing enabled. See Dexterity manual for further information

Resources