Reputation: 951
I created an app with the cake bake command, and one table used text as a field type.
All worked out well, a textarea was generated for that field and it works as expected. I saved a few entries, viewed them edited a few.
I realised that one entry did not populate the textarea when using edit. It displays correctly in the view, but when editing the data is not in the textarea and saving that causes all the information to go missing.
And this happened with from a normal baked table.
here is the value I used it the textarea:
Morning Christopher,
Please can you send me the password for our email accounts at Citano as we need it to reset my directors email account for his blackberry.
· Your urgent response is required in this matter.
Jaques Kruger Citano Distributors.
Yes there is a strange character in there, I think a bullet point from word.
Is this a framework bug, that was fixed later? I tested on 1.3.10 and 1.3.8 .
Any help would be appreciated.
Edit:
Here is the standard baked view "edit.ctp":
<div class="tickets form">
<?php echo $this->Form->create('Ticket', array('type'=>'file'));?>
<fieldset>
<legend><?php __('Edit Ticket'); ?></legend>
<?php
echo $this->Form->input('Ticket.id');
echo $this->Form->input('Ticket.name', array('label' => 'Ticket name'));
echo $this->Form->input('Ticket.details'); # Problem textarea not populating
echo $this->Form->input('Ticket.user_id', array('label' => 'Assigned to'));
echo $this->Form->input('Ticket.queue_id');
echo $this->Form->input('Ticket.client_id', array('options' => $clients,'default' => $defaultClient,'empty' => 'None'));
echo $this->Form->input('Ticket.status', array('options' => $ticketStatus));
echo $this->Form->input('Ticket.accepted', array('type' => 'checkbox'));
echo $this->Form->input('Ticket.linkedticketid', array('options' => $linkTickets,'empty' => 'None','style' => 'width:100%;','label' => 'Linked ticket'));
echo $this->Form->input('Ticket.due_date');
echo $this->Form->file('attachment');
echo $this->Form->input('email', array('label' => 'Additional email to mailing list'));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">
<h3><?php __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('View Ticket', true), array('action' => 'view', $this->Form->value('Ticket.id'))); ?> </li>
<li><?php echo $this->Html->link(__('List Ticket', true), array('action' => 'index')); ?> </li>
</ul>
</div>
And here is the controller:
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid ticket', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Ticket->save($this->data)) {
$this->Session->setFlash(__('The Ticket has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Ticket could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Ticket->read(null, $id);
}
}
As I said before, the data has already been added, and there is nothing wrong with the data, but when editing the textarea does not always populate with existing data, while the rest of the fields always populates with existing data.
Debug Data in edit.ctp
Array
(
[Ticket] => Array
(
[id] => 281
[linkedticketid] =>
[user_id] => 1
[queue_id] => 4
[name] => password
[details] => Morning Christopher,
Please can you send me the password for our email accounts at Citano as we need it to reset my directors email account for his blackberry.
� Your urgent response is required in this matter.
Jaques Kruger
Citano Distributors.
[status] => 0
[accepted] => 0
[due_date] => 2011-11-12
[mailedtech] => 1
[uuid] => 34b12707-0b87-11e1-97b4-001e90d15e95
[created] =>
[modified] => 2011-11-10 12:48:51
)
[User] => Array
(
[id] => 1
[group_id] => 1
[name] => Christopher
[username] => Nightwolf
[password] => 8be1083780671a3b3541ff82r161d3d55a4e5d79
[email] => [email protected]
[created] => 2011-09-05 13:30:56
[modified] => 2011-09-05 13:31:34
)
[Queue] => Array
(
[id] => 4
[name] => Christopher
[rank] => 20
[created] => 2011-09-05 13:58:40
[modified] => 2011-09-05 13:58:40
)
[Task] => Array
(
)
[Ticketforclient] => Array
(
[0] => Array
(
[id] => 95
[ticket_id] => 281
[client_id] =>
[created] => 2011-11-10 12:34:45
[modified] => 2011-11-10 12:48:51
)
)
[Ticketnote] => Array
(
)
[Ticketsinqueue] => Array
(
[0] => Array
(
[id] => 67
[ticket_id] => 281
[queue_id] => 4
[created] =>
[modified] => 2011-11-10 12:48:50
)
)
[Activitylog] => Array
(
)
[Billinginfo] => Array
(
)
[Attachment] => Array
(
)
[Ticketmailinglist] => Array
(
[0] => Array
(
[id] => 11
[ticket_id] => 281
[emailaddress] => [email protected]
[originalsender] => 0
)
)
)
Upvotes: 0
Views: 4173
Reputation: 2224
Make sure ~/app/config/core.php
use this:
Configure::write('App.encoding', 'UTF-8');
Layout section
<?php echo $html->charset(); ?>
Database Config
class DATABASE_CONFIG {
public $default = array(
...
'encoding' => 'utf8'
);
}
And Read This
http://book.cakephp.org/view/1616/x1-3-improvements
Upvotes: 7
Reputation: 951
This is a bad way of doing it according to me, but it is the only way that I know how.
The cakephp's textarea formhelper seem to exclude the textarea content due to strange value in database. Here is the form helper:
echo $this->Form->input('Ticket.details');
Here is the html it supposed to generate:
echo '<textarea name="data[Ticket][details]" cols="30" rows="6" id="TicketDetails">'.$ticketDetail.'</textarea>';
$ticketDetail is the content from the database.
By using the written out html all works perfectly.
Upvotes: 1
Reputation: 1110
� Your urgent response is required in this matter.
If it's showing up in debug too, then one would assume that it's a problem with your data. Paste the source text into notepad or similar and try again to see if it cleared the problem character out. =)
edit
If you have no control over the entered characters, then you might want to consider encoding the text that your users enter into a known format, and then whitelisting acceptable characters with a regex. That will prevent odd characters from sneaking in permanently. =)
Upvotes: 0
Reputation: 14905
I suspect that the odd character is breaking the rendering of HTML on the web browser side.
Have you taken a look at the generated HTML? Does the text show up in the textarea on the source view (Ctrl+U on Firefox)?
If that doesn't give you enough information, try installing Wireshark, and logging the request and response. It has a hex view that should allow you to see exactly what the character is.
You may have to filter what characters can be inserted into the database, and what can be displayed in the textarea to conform to ASCII.
Upvotes: 0