Note that there are some explanatory texts on larger screens.

plurals
  1. POcakephp default values only using first character
    text
    copied!<p>I'm creating a cakephp app with a form that has generated default values (right now it's only placeholder data until this gets resolved) which get thrown into a table. The form works, it inserts the record fine, but for some reason the form is only using the first character of the default values. So for instance, "Title" only has the character "t" in the form, "Content" only has "c", etc. </p> <p>When I pr($this->data), all the placeholder data is there. I can edit them and add more text which is saved fine, so it's not a form field length issue. Somewhere between $this->data and $this->Form->input, the defaults are getting truncated. I don't know where to begin troubleshooting this. I couldn't find anything here, and I could only find one mention of this problem by googling it, which wasn't resolved.</p> <p>Cakephp 1.3.6, PHP 5.3.3, Linux</p> <p>Thanks for your help</p> <p>Results of pr($this->data):</p> <pre><code>Array ( [title] =&gt; title [content] =&gt; content [media_url] =&gt; media_url ) </code></pre> <p>View:</p> <pre><code>&lt;? pr($this-&gt;data); ?&gt; &lt;div class="generators form"&gt; &lt;?php echo $this-&gt;Form-&gt;create('Generator');?&gt; &lt;fieldset&gt; &lt;legend&gt;Create New Post&lt;/legend&gt; &lt;?php echo $this-&gt;Form-&gt;input('title'); echo $this-&gt;Form-&gt;input('content'); echo $this-&gt;Form-&gt;input('publish_date'); echo $this-&gt;Form-&gt;input('media_url'); ?&gt; &lt;/fieldset&gt; &lt;?php echo $this-&gt;Form-&gt;end('Create Post');?&gt; &lt;/div&gt; </code></pre> <p>Controller:</p> <pre><code>&lt;?php class GeneratorsController extends AppController { var $name = 'Generators'; function posts() { // save the post if (!empty($this-&gt;data)) { $this-&gt;Generator-&gt;create(); if ($this-&gt;Generator-&gt;save($this-&gt;data)) { $this-&gt;Session-&gt;setFlash(__('The post has been created', true)); $this-&gt;redirect(array('action' =&gt; 'posts')); // TODO: call posting app } else { $this-&gt;Session-&gt;setFlash(__('There was a problem. Please, try again.', true)); } } else { // create post $this-&gt;data['title'] = "title"; $this-&gt;data['content'] = "content"; //$this-&gt;data['publish_date'] = ""; $this-&gt;data['media_url'] = "media_url"; } } } ?&gt; </code></pre> <p>Model:</p> <pre><code>&lt;?php class Generator extends AppModel { var $name = 'Generator'; var $displayField = 'title'; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload