I want to use form to set a user data.
This is my code.It is garbled when enter the Japanese.
However, it works well when i exclude 'type' => 'file'.
Configuration and database is set to utf8 all.
Please give to advice.
echo $this->Form->create('User', array('url' => array('controller' => 'Users', 'action' => 'userprofileedit',$user_id ),'type' => 'file'));
echo $this->Form->input('upfile', array('label' => array('text' => 'upfile'),'type' => 'file'));
echo $this->Form->input('nickname',array('label' => array('text' => 'nickname'),"value"=>$nickname));
echo $this->Form->end(__('Save'));
If you are uploading a file for the User, replace the form creation:
echo $this->Form->create('User', array(
'url' => array('controller' => 'Users', 'action' => 'userprofileedit',$user_id ),
'type' => 'file'
));
with:
echo $this->Form->create('User', array(
'enctype' => 'multipart/form-data'
'url' => array('controller' => 'Users', 'action' => 'userprofileedit',$user_id ),
));
Also make sure that your app/core.php has:
Configure::write('App.encoding', 'UTF-8');
Related
My task is to upload file to folder and its details to database its working fine if i have one record in a form but if i have multiple rows then its really giving errors i searched out for many links but couldn't find the answer.
Used save All, Save Many, all functions but still unable to perform it.
Please provide full code if anyone can.
My Controller
public function add()
{
if ($this->request->is('post'))
{
$this->File->create();
if(empty($this->data['File']['url']['name']))
{
unset($this->request->data['url']['file']);
}
if(!empty($this->data['File']['url']['name']))
{
$file=$this->data['File']['url'];
$file['name']=$this->sanitize($file['name']);
$this->request->data['File']['url'] = time().$file['name'];
if($this->File->save($this->request->data))
{
move_uploaded_file($file['tmp_name'], APP . 'outsidefiles' .DS. time().$file['name']);
return $this->redirect(array('action' => 'index'));
$this->Session->setFlash(__('Your File has been saved.'));
//return $this->redirect(array('action' => 'index'));
}
}
$this->Session->setFlash(__('Unable to add your File.'));
}
}
.ctp file
<h1>Add File</h1>
<?php
echo $this->Form->create('File',array('enctype'=>'multipart/form-data'));
echo $this->Form->input('category', array(
'options' => array( 'passport' => 'Passport', 'pancard' => 'Pancard', 'driving license' => 'Driving License', 'others' => 'Others')
));
echo $this->Form->input('type', array(
'options' => array( 'image' => 'Image', 'office' => 'Office', 'technical' => 'Technical', 'others' => 'Others')
));
echo $this->Form->input('reference');
echo $this->Form->input('url', array('type' => 'file'));
echo $this->Form->input('category', array(
'options' => array( 'passport' => 'Passport', 'pancard' => 'Pancard', 'driving license' => 'Driving License', 'others' => 'Others')
));
echo $this->Form->input('type', array(
'options' => array( 'image' => 'Image', 'office' => 'Office', 'technical' => 'Technical', 'others' => 'Others')
));
echo $this->Form->input('reference');
echo $this->Form->input('url', array('type' => 'file'));
echo $this->Form->end('Save File');
?>
Auth Flash params are not working for me.
AppController:
class AppController extends Controller {
public $helpers = array(
'Session',
'Facebook.Facebook',
'Html' => array('className' => 'BoostCake.BoostCakeHtml'),
'Form' => array('className' => 'BoostCake.BoostCakeForm'),
'Paginator' => array('className' => 'BoostCake.BoostCakePaginator'),
'AssetCompress.AssetCompress',
'PhpThumb.PhpThumb'
);
public $components = array(
'Session',
'RequestHandler',
'Auth' => array(
'authenticate' => array('Custom'),
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'index'),
'flash' => array(
'element' => 'alert',
'key' => 'auth',
'params' => array(
'plugin' => 'BoostCake',
'class' => 'alert-danger'
)
)
),
);
Default layout:
Session->flash();
echo $this->Session->flash('auth');
echo $this->fetch('content');
?>
I've debugged the params to make sure they're outputting correctly, but when the alert pops up this is what I see:
<div id="authMessage" class="message">Username or password is incorrect</div>
Thanks in advance
You need to create a ctp with the name alert.ctp in your view as follows:
<div id="authMessage" class="message">
<?php
echo $plugin;
echo $class;
?>
Username or password is incorrect
</div>
Have a look at this CakePHP custom flash for loginError
firstCode
echo $this->Form->create('User', array(
'id' => 'form-login',
'inputDefaults' => array(
'label' => false,
'div' => false,
)
));
Second Code
echo $form->create('User', array('url' => array('controller' => 'users', 'action' => 'login')));
sorry to ask this silly question.i want to merge second code into firstone ..as they are working fine independently.. i have tried many times but failed
You're probably mixing up the arrays. Should all be in one big array (as the create() method only takes 2 arguments), like this:
echo $this->Form->create('User', array(
'url' => array('controller' => 'users', 'action' => 'login'),
'id' => 'form-login',
'inputDefaults' => array('label' => false, 'div' => false)
));
Using CakePHP 1.3 I am trying to get routers with language, slug, pagination, order .
Currently I have these:
Router::connect('/', array('controller' => 'pages', 'action' => 'index'));
Router::connect("/:controller/:slug", array('action' => 'view'), array('pass' => array('slug')));
Router::connect("/:lang", array('controller' => 'pages', 'action' => 'index'), array('lang' => 'fr|en|de'));
Router::connect("/:lang/:controller/:slug", array('action' => 'view'), array('lang' => 'fr|en|de', 'pass' => array('slug')));
and those are working with language and slug set or slug and pagination , but all three of them fails:
OK - /pages/view/page-slug/page:2
OK - /fr/pages/page-slug
FAIL - /pages/view/page-slug/page:2/lang:fr
I have tried
<?php $this->Paginator->options(array('url' => $this->passedArgs)); ?>
before the paginator but still the same result
Just try this code
Router::connectNamed(array('language','pagination','order','slug'));
Router::connect('/lang/pagination/:slug:order', array(
'plugin' => false,
'controller' => 'pages',
'action' => 'index',
),array(
"pass"=>array("lang","pagination","slug","order")
),array(
'pagination' => '[0-9]+',
'order' => '[0-9]+',
)
);
I have built a screen where an administrator can add and edit users. I'm able to add users without issue, but when I was testing how users can be edited, I noticed that if I have more than one user, I'm only be able to edit the last user thats listed. I'm unable to edit any other user.
Here is my code:
<?php foreach ($personel as $person) { ?>
<div id="edituser<?php echo $person['Personel']['id']; ?>" class="modal" style="display:none;">
<?php
$edituserformname = "editUser" + $person['Personel']['id'];
?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit User - <?php echo $person['Personel']['firstname']; ?> <?php echo $person['Personel']['surname']; ?></h3>
</div>
<div class="modal-body iframed">
<?php echo $
<?php
echo $this->Form->create('Personel', array(
'class' => 'form-horizontal',
'id' => $edituserformname
));
echo $this->Form->input('id', array(
'type' => 'hidden',
'value' => $person['Personel']['id']
));
echo $this->Form->input('firstname', array(
'type' => 'text',
'label' => 'First Name',
'class' => 'span5',
'value' => $person['Personel']['firstname']
));
echo $this->Form->input('surname', array(
'type' => 'text',
'label' => 'Surname',
'class' => 'span5',
'value' => $person['Personel']['surname']
));
echo $this->Form->input('email', array(
'type' => 'text',
'label' => 'E-Mail',
'class' => 'span5',
'value' => $person['Personel']['email']
));
echo $this->Form->input('companyid', array(
'type' => 'hidden',
'value' => $company['Company']['id']
));
echo $this->Form->input('accesslevel', array(
'label' => 'Access Level',
'options' => $roles,
'empty' => 'Select Access Level',
'class' => 'span5',
'value' => $person['Personel']['accesslevel']
));
$pocval = array('1' => 'Yes', '0' => 'No');
echo $this->Form->input('poc', array(
'label' => 'Point of Contact?',
'options' => $pocval,
'value' => $person['Personel']['poc']
));
echo $this->Form->input('password', array(
'type' => 'text',
'label' => 'Password',
'class' => 'span5',
'value' => $company['Personel']['password']
));
echo $this->Form->input('telephone', array(
'type' => 'text',
'label' => 'Telephone',
'class' => 'span5',
'value' => $company['Personel']['telephone']
));
echo $this->Form->input('type', array(
'type' => 'hidden',
'value' => '0'
));
?>
</div>
<div class="modal-footer">
<?php
echo $this->Form->submit('Save & Close', array(
'type' => 'submit',
'class' => 'btn btn-primary',
'id' => 'editusermodal'
));
echo $this->Form->end();
?>
</div>
</div>
<?php } ?>
How can I fix this issue? I had an idea about using iFrame's but I'm reluctant to use this method. I'd rather be able to do it through CakePHP.
Many thanks
You don't need to use iFrame's. It doesn't work because your Form doesn't close correctly.
The $this->Form->create() and $this->Form->end() should be outside the divs.
Try the following:
<?php
echo $this->Form->create('Personel', array(
'class' => 'form-horizontal',
'id' => $edituserformname
));
?>
<div class="modal-body iframed">
<?php
echo $this->Form->input('id', array(
'type' => 'hidden',
'value' => $person['Personel']['id']
));
echo $this->Form->input('firstname', array(
'type' => 'text',
'label' => 'First Name',
'class' => 'span5',
'value' => $person['Personel']['firstname']
));
echo $this->Form->input('surname', array(
'type' => 'text',
'label' => 'Surname',
'class' => 'span5',
'value' => $person['Personel']['surname']
));
echo $this->Form->input('email', array(
'type' => 'text',
'label' => 'E-Mail',
'class' => 'span5',
'value' => $person['Personel']['email']
));
echo $this->Form->input('companyid', array(
'type' => 'hidden',
'value' => $company['Company']['id']
));
echo $this->Form->input('accesslevel', array(
'label' => 'Access Level',
'options' => $roles,
'empty' => 'Select Access Level',
'class' => 'span5',
'value' => $person['Personel']['accesslevel']
));
$pocval = array('1' => 'Yes', '0' => 'No');
echo $this->Form->input('poc', array(
'label' => 'Point of Contact?',
'options' => $pocval,
'value' => $person['Personel']['poc']
));
echo $this->Form->input('password', array(
'type' => 'text',
'label' => 'Password',
'class' => 'span5',
'value' => $company['Personel']['password']
));
echo $this->Form->input('telephone', array(
'type' => 'text',
'label' => 'Telephone',
'class' => 'span5',
'value' => $company['Personel']['telephone']
));
echo $this->Form->input('type', array(
'type' => 'hidden',
'value' => '0'
));
?>
</div>
<div class="modal-footer">
<?php
echo $this->Form->submit('Save & Close', array(
'type' => 'submit',
'class' => 'btn btn-primary',
'id' => 'editusermodal'
));
?>
</div>
<?php
echo $this->Form->end();
?>
If you want more than one record editing at a time you can use the following
$this->Form->input('ModelName.n.field_name', $options);
So to do all of them run this in a loop:
echo $this->Form->create(); // only one start
foreach($users as $k => $user) {
echo $this->Form->id(sprintf('Personel.%s.id', $k), array(
'value' => $user['Personel']['id']
));
echo $this->Form->input(sprintf('Personel.%s.field', $k), array(
'value' => $user['Personel']['field']
));
// etc
}
echo $this->Form->end(); // only one end
To save them all you can use saveAll()
$this->Personel->saveAll($this->data['Personel']);