strange id added on form create url cakephp
I found something strange on cakephp when i create form using FormHelper, a strange id appear on the action url. So i have this code on my view
<?php echo $form->create('Evoucher', array('url' => array('controller' => 'gift_vouchers', 'action' => 'buy', $giftVoucher['GiftVoucher']['amount'])));?>
It is generated a form tag with strange id added on action url. Something like this
<form id="EvoucherBuyForm" method="post" action="/gift_vouchers/buy/2/20" accept-charset="utf-8">
After exploration, i found the problem was on the controller action for buy. I have set id for the data variable
$this->data['Evoucher']['id'] = 2;
So after taking out this line, i change it into
$this->Evoucher->id = 2;
And cakephp can generate correct action url for the form tag
<form id="EvoucherBuyForm" method="post" action="/gift_vouchers/buy/20" accept-charset="utf-8">
I hope this tutorial help you. Thanks for visiting our blog