In cakephp 3 I got error Unexpected field in POST data - cakephp-3.2

In cakephp 3 I got error Unexpected field in POST data.
Actually that field is not in my table, but I want to use in controller.

The Security Component in CakePHP is not forgiving. If you want to allow a field thru that should not go thru the Security Component hashing process, you need to use the unlockedField method that comes with the FormHelper class as such:
$this->Form->unlockField('field');
If this does not work, you will need to provide us with the pertinent code

I was getting the similar error in cakephp 3.4 I was using the simple html form and input fields. I was passing the input fields data in array. like below:-
<form action="" method="post">
<input name="data[1][category_1]" id="category_1">
</form>
Then i do some R&D and found that we need to use the cakephp form helper to create the form and its fields like below :-
In case of pass form data in array
<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
<?= $this->Form->input("Data.1.category_1"); ?>
<?= $this->Form->end() ?>
In case of simple input fields you can do the code like below
<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
<?= $this->Form->input("category"); ?>
<?= $this->Form->end() ?>
This work form me and resolve the error Unexpected field in POST data in cakephp 3.4

Related

Symfony 2.3: The "actions" extension is not enabled

I am currently updating a Symfony 2.1 project to Symfony 2.3 (and later to 3.4).
I just got the error message The "actions" extension is not enabled.. Can someone tell me where I can find the fault? Google could not help me unfortunately....
thanks
Anton
Take a look at the Symfony 2.1 to 2.2 upgrade guide:
FrameworkBundle
The render method of the actions templating helper signature and
arguments changed:
Before:
<?php echo $view['actions']->render('BlogBundle:Post:list', array('limit' => 2), array('alt' => 'BlogBundle:Post:error')) ?>
After:
<?php echo $view['actions']->render($view['router']->generate('post_list', array('limit' => 2)), array('alt' => 'BlogBundle:Post:error')) ?>
where post_list is the route name for the BlogBundle:Post:list controller, or if you don't want to create a route:
<?php echo $view['actions']->render(new ControllerReference('BlogBundle:Post:list', array('limit' => 2)), array('alt' => 'BlogBundle:Post:error')) ?>
Does this lead you on the right track?

can't view html content when submit form in wordpress

i'm was create a menu and Form in wordpress.
then, i was create form send email for my customer.
it's oke. But my problems is :
I'm writing some thing in editor, add color, font size... for text, add images....
But when echo the result after click submit button, it not show same as in the editor content,
all html code was removed, (the heading form h1 -> h6 is keep).
I want the result of Echo was same as in the forms. (All html was keep)
Help me to solve this problem, Please !
here is my code
<form method="post" id="kaka" name="form_send_mail">
<?php wp_editor('default text', 'idgiday', $settings = array(
'drag_drop_upload' => true,
'editor_height' => '300',
'textarea_name' => 'textarea_name_td'
) );
?>
<imput type="text"></imput>
<input type="submit" value="ok">
</form>
<?php
echo #$_POST['textarea_name_td'];
?>
Actually you need to get the output via editor ID which you have mentioned idgiday ,
echo $_REQUEST['idgiday'];
You can save the editor output via,
add_post_meta($post_id,'idgiday',$_REQUEST['idgiday']);
And then get the output,
get_post_meta($post_id,'idgiday',true);

Custom metabox for file upload return empty filename

I want to attach a file to a post and "do something with it later". The file isn't being pulled over when I publish/update my post, the error I get is an empty filename. If I change the input type to text and submit I can get the text to save/display but trying to upload the file acts as though I haven't supplied the file to the form:
form --
function display_file_upload_meta_box($post_id,$post){
wp_nonce_field( basename( __FILE__ ), 'file_upload_meta_box_nonce' );
?>
<p>
<?php
$fileUpload= get_post_meta($object->ID,'file-upload-meta',true);
if(!$fileUpload)
$fileUpload = '';
echo 'file: '.$fileUpload;
?>
<label for="file_upload_meta">Attach a file to this post</label>
<input type="file" id="file_upload_meta" name="file_upload_meta" class="widefat"/>
</p>
<?php
}
code to upload file --
$new_meta_value = wp_upload_bits($_FILES["file_upload_meta"]['name'], null, file_get_contents($_FILES["file_upload_meta"]['tmp_name']));
It's probably because the form does not have those attributes :
enctype="multipart/form-data" encoding="multipart/form-data"
You can use a hook to add them, check this : https://gist.github.com/rfmeier/3513349
I got a requirement for adding custom meta boxes for a custom post type in wordpress and I tried using the following plugin and got working for me. Try this

How to add class to Form in Yii framework?

I have a form in Yii, and I want to add a class to the form :
<form class="subscribe_form" action="#" method="post">
I tried this but it's not working :
<?php $form=$this->beginWidget('CActiveForm', array(
'class'=>'subscribe_form',
'id'=>'mail-list-addmail-form',
'enableAjaxValidation'=>false
)); ?>
Thanks for helping me!.
You need to pass an htmlOptions property, like this:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'mail-list-addmail-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array(
'class'=>'subscribe_form',
)
)); ?>
from http://www.yiiframework.com/doc/api/1.1/CActiveForm#htmlOptions-detail
htmlOptions: additional HTML attributes that should be rendered for the form tag.
htmlOptions: there is commonly through all HTML helpers CHtml, CActiveForm and you can set the custom HTML options in this property.

Override form using PHPTemplate

I was wondering how I should override the way a form looks in Drupal 7 using PHPTemplate. I have some difficulties displaying all the information on my page.
I have a page with a form and some miscellaneous information.
I have tried:
foo.module
function foo_add_form($form, &$form_state, $foo) {
...
$form['#theme'] = 'foo_add';
return $form;
}
function foo_theme($existing, $type, $theme, $path) {
return array(
'foo_add' => array(
'template' => 'foo-add',
'render element' => 'form',
),
);
}
foo-add.tpl.php
<?php
// First form
print drupal_render_children($form);
?>
<!-- Miscellaneous information -->
<div id="links">
<ul>...</ul>
<form action="#" method="post" id="second-form">
<fieldset id="i-want">
...
</fieldset>
...
</form>
</div>
At the moment the form and miscellaneous information are being displayed. However, the 2nd form (id="second-form") is being removed somehow. I can see it in the source, but when I inspect the element with chrome/firefox, I can no longer see the form element. I can see the div, ul and fieldset tags though.
Has anybody done this before?
Typically, you wouldn't add to the form at the theme layer. Instead, you'd use a custom module, implementing hook_form_alter to modify the form.

Resources