Having a problem where we are creating a form that takes a varchar, but cakephp sees the field as an int.
So how would we fix it?
Here is our add function to add a relationship.
public function add() {
$this->set('title_for_layout', 'Send A Relationship Request');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.jpg');
$this->layout='home_layout';
if ($this->request->is('post')) {
$this->Relationship->set($this->request->data);
if ($this->Relationship->validates(array('fieldList'=>array('receiver_id','Relationship.userExists'))))
{
$username=$this->Relationship->username;
$this->Relationship->save($this->request->data);
$this->Session->setFlash('The relationship has been saved');
} else {
$this->Session->setFlash('The relationship could not be saved. Please, try again.');
}
}
}
And here is our view (a form which asks for the username (varchar))
<?php
echo $this->Form->create('Relationship', array('action'=>'add'));
echo $this->Form->input('sender_id',array('label'=>'Enter your username: '));
echo $this->Form->input('receiver_id',array('label'=>'Username of user: '));
echo "<br />";
echo $this->Form->end('Click here to add relationship');
?>
it is due to your naming convention. Sender_id and receiver_id will be treated as integer value by default because it represents as relationship belongs to sender and relationship belongs to receiver, for better result you can change the naming convention of fields or use this code :