Question

In my application i am using security component and defined in the app controller like this

public $components = array('Security');

And i have created the form like this

<?php
    echo $this->Form->create('Admin', array('id' => 'form',"url"=>array("plugin"=>"admins","controller"=>"admins","action"=>"save","admin"=>true)));
    echo $this->Form->hidden("submit_type",array("id" => "id_submit_type","value" => ""));
    echo $this->Form->input("username");
    echo $this->Form->input("password");
    echo $this->Form->button(__('Save'),array("id" => "save","class" => "form-button"));
    echo $this->Form->button(__('Save & Cont'),array("id" => "savec","class" => "form-button"));
    echo $this->Form->end();
?>

And in Javascript am updating the hidden field value like this

<script type="text/javascript">
    $(document).ready(function() 
    {
        $('#save, #savec').click(function() {

            if($(this).is('#save'))
                $('#id_submit_type').val("S");
            else
                $('#id_submit_type').val("C");
            $('#form').submit();
        });


    });
 </script>

After click on save button

CORE/Cake/Controller/Component/SecurityComponent.php line 234 → SecurityComponent->blackHole(AdminsController, string)
[internal function] → SecurityComponent->startup(AdminsController)
CORE/Cake/Utility/ObjectCollection.php line 131 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 247 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 670 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 183 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 161 → Dispatcher->_invoke(AdminsController, CakeRequest, CakeResponse)
APP/webroot/index.php line 97 → Dispatcher->dispatch(CakeRequest, CakeResponse)

If i am commenting to update the hidden fields in javascript

my functionality is working fine and saving the data into table

please tell me how to set the hidden variable values in javascript while we are using security component

Was it helpful?

Solution

Try like this, i don't know is it a correct solution or not.But it's working properly for me. write the below code in your beforeFilter function

$this->Security->disabledFields = array('hiddenfield1', 'hiddenfield2'); // set the hidden fields like this
function beforeFilter() {
       $this->Security->disabledFields = array('submit_type');  // for your code
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top