Object provided to Escape helper, but flags do not allow recursion on hidden field - zend-framework

Okay this is a weird one to me...Usually i get this error when there's a problem with the date/time format, but it's throwing up on a hidden field, even though it's set to view formhidden...Has this happened to anyone before?
That's the view:
echo $this->formHidden($steppedEdge->get('glassSections'));
This is the form fieldset:
$this->add([
'name' => 'glassSections',
'type' => \Zend\Form\Element\Hidden::class,
'attributes' => [
'id' => 'glassSections',
],
]);
Any advice would be appreciated!

It's because it was an entity in that field...

Related

TYPO3 TCA and select form

I try to get values for my tca:
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['Herr', 0],
['Frau', 1]
],
'size' => 1,
'maxitems' => 2,
'eval' => 'required'
],
my form.html has this select types:
<label>Anrede</label>
<f:form.select name="salutation" class="form-control">
<f:form.select.option value="0">Herr</f:form.select.option>
<f:form.select.option value="1">Frau</f:form.select.option>
</f:form.select>
but i get always the first item: Herr, can somebody tell me what i am doing wrong?
For frontend forms with Extbase you will need a proper TypoScript conffiguration, a PHP newAction and/or createAction method and your Fluid template.
Based on the additional information now there are two options that came to my mind:
Either the validation and storage of your form values is not
configured properly, so they will be removed on the way to the
database.
Or you might have rendered the field twice with the same name in the
frontend form, thus making the last entry the winner.
So please double check the fields first before digging deeper into the storage process.
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/7-Controllers/1-Creating-Controllers-and-Actions.html

Disable field in the crud

I need to update a record, but I want to display some fields as disabled for editing. I don't want to let the user edit a certain field, but I want to display them
If I understand your problem correctly then you may want to try something like this.
CRUD::addField([
'name' => 'nameOfYourField',
'label' => 'nameOFLabel',
'type' => 'number',
'attributes' => [
'readonly' => 'readonly',
],
]);
You can also use 'disabled' => 'disabled', but it depends what you want exatly to achieve with the values.
Check it out here

Assert\Expression gives Variable Not Valid around position 2

I have a form. I am trying to assert that if one field is not null, then another field must also not be null. Trying to do this with Symfony annotations as I don't want the code in the controller and was told this would be a good way to do it.
I have tried using an Assert\Expression, however I keep getting various errors on the field that I am checking. It's slightly concerning that it says Variable when I need it to be referring to a field.
// The field that I want to check if it is null
'activeTestData',
null,
[
'label' => 'form.label.active_test_data',
'required' => false,
]
)
->add(
// The field that can't be null if the activeTestData field is not null
'activeTestDataUnit',
ChoiceType::class,
[
'label' => 'form.label.active_test_data_unit',
'required' => false,
'choices' => [
'form.label.active_test_please_select' => '',
'Byte(s)' => 'b',
'Kilobyte(s)' => 'k',
'Megabyte(s)' => 'm',
'Gigabyte(s)' => 'g',
],
// Where I am having the issue
'constraints' => [
new Assert\Expression([
'expression' => "!activeTestData == null",
'message' => 'Please enter a unit for active test data'
]),
],
I want a FORM error for when there is nothing in activeTestDataUnit but there is something in activeTestData. Unfortunately I get a symfony error:
Variable "activeTestData" is not valid around position 2 for expression !activeTestData == null.
Correct syntax for this situation would be the following:
"!this.getParent().get('activeTestData')->getData() == null"
You can see more examples and details on symfony documentation.
I updated my answer. In this context "this" is a Form object of a "activeTestDataUnit" field. So to check for a "activeTestData" value you have go to to the parent and then get a correct child.
As of Symfony 4.1 you can pass your custom values to the "values" argument and avoid all of this clutter, by passing $builder->getData(). See here for the more information on symfony documentation

ZF3 form element classes get encoded with unicode entities

I'm trying to figure out why ZF3 encodes my element's class string, but can't find anything about that behaviour on the internet.
$this->add([
'type' => 'Button',
'name' => 'submitLogin',
'options' => [
'label' => '<i class="zmdi zmdi-check"></i>',
'label_options' => [
'disable_html_escape' => true,
]
],
'attributes' => [
'type' => 'submit',
'class' => 'btn btn--icon login__block__btn',
],
]);
becomes
<button type="submit" name="submitLogin" class="btn btn--icon login__block__btn" value=""><i class="zmdi zmdi-check"></i></button>
I think this is an abstract concept. Generally we take some steps when we work with data. We filter input values and escape outputs. This is a security philosophy.
Zend Framework did the same thing while something is about security. This means this behavior is by default. ZF escapes attributes' values when it is being displayed onto the browser. ZF only allows non-escaping through explicit options like you did for the label's content above.
You will get some concept via this issue on github where Matthew said:
Secure by default is the mantra

$this->request->data EMPTY - When I have disabled Fields CakePHP 2

I have a form which has some disabled fields, when the form is submitted both $this->request->data and $_POST is empty, removing the disabled fields and it is fine again. I would have though it would still pass though the non-disabled fields. I've even tried to remove the disabled field attribute when the submit button is pushed but this still returns an empty array.
Is there something cake related that might be causing this?
Thanks
// SNIPPET FROM THE VIEW CODE:
$this->Form->create('Card', array('class' => 'GeneralValidate'));
$this->Form->input('Card.property_id', array('type'=>'select', 'empty'=>true , 'class' => 'required adminOnlyField', 'div' => array('class' => 'required')));
$this->Form->input('Card.building_id', array('type'=>'select', 'empty'=>true, 'id' => 'BuildingSelector', 'class' => 'adminOnlyField', 'label' => 'Building (If Applicable)'));
$this->Form->input('Prospect.waiting_list_details', array('value' => $prospect['Prospect']['waiting_list_details']));
$this->Form->input('SaleDetail.property_sold', array('class' => 'checkbox', 'checked' => $ps_checked));
$this->Form->input('SaleDetail.date_conditions_met', array('type'=>'text', 'class' => 'text date_picker adminOnlyField', 'value' => $this->Date->format($saledetail['SaleDetail']['date_conditions_met'])));
$this->Form->button('Save & Continue', array('type'=>'submit', 'label' => 'Save', 'name' => 'quicksave' , 'class' => 'submit long clear_ready_only'));
// JS FROM THE VIEW
$(function () {
var $adminOnly = $('.adminOnlyField');
$adminOnly.prop('disabled',true).prop('readonly',true);
$adminOnly.attr("onclick","return false");
$adminOnly.attr("onkeydown","return false");
$adminOnly.removeClass('required');
$adminOnly.removeClass('date_picker');
$('.clear_ready_only').click(function(e)
{
e.preventDefault();
$adminOnly.prop('disabled',false).prop('readonly',false);
$adminOnly.attr("onclick","return true");
$adminOnly.attr("onkeydown","return true");
$('#CardModifysaleForm').submit();
});
});
That's the way HTML works, disabled don't get posted. CakePHP can't change what is sent from the browser. If you still want the value you can set it as a hidden element.
Update
Some problems I see:
Missing Form::end() in view (always a good idea to insert it).
You never said your form was submitted from JS, first test with a simple form POST then JS.
Your JS code is set to submit a form by ID CardModifysaleForm. There's no such ID in your supplied view code and you're not setting your form to that ID from the snippet you supply.
I ended up removing the disabled option from this, leaving the ready only and added some addition CSS stylings so it looked disabled to the user. This is not the exact answer to the question but works as a different approach.