Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP does not auto-populate a field (that has no Model) after submission
    text
    copied!<h1>The situation</h1> <p>I'm working on a large form which have been split into several tabs, both to group fields of a kind and make filling easier. The tabs are activated using JavaScript (jQuery) and the form is submitted whole (all tabs at once, even if there are blank fields).</p> <p>I am trying to submit a <code>hidden</code> field along with the form to keep user's current tab. This way, when the form is submitted, data is saved and the user goes back to the very same tab it was before. This field is not attached to any Model, as it is just a <em>helper</em>.</p> <h1>The problem + what have I tried</h1> <p>The field is correctly populated by <a href="/questions/tagged/jquery" class="post-tag" title="show questions tagged 'jquery'" rel="tag">jquery</a> as the user switch tabs, and it is submitted along with the form. This is what I did:</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;create('Briefing', array('enctype' =&gt; 'multipart/form-data')); // This is my aux field, which is populated via jQuery as user switch tabs echo $this-&gt;Form-&gt;hidden('tab-active', array('name' =&gt; 'tab-active', 'id' =&gt; 'tab-active')); echo $this-&gt;Form-&gt;input('title'); echo $this-&gt;Form-&gt;submit('Save', array('class' =&gt; 'btn btn-success')); echo $this-&gt;Form-&gt;end(); ?&gt; </code></pre> <p>Let's suppose the user submitted the form when it was at "Tab #4". When I <code>debug($this-&gt;data);</code> at my <code>BriefingsController</code>, this is what I get:</p> <pre><code>/app/Controller/BriefingsController.php (line 133) array( 'tab-active' =&gt; 'tab-4', 'Briefing' =&gt; array( 'title' =&gt; 'My test title' ) ) </code></pre> <p>So my Controller receives the form data for both <code>tab-active</code> and <code>Briefing.title</code> fields, but when the form is loaded after submission, only the Model field is populated with the submitted data, and <code>tab-active</code> comes with an empty value. CakePHP <em>does not auto populate the value for my non-model-attached field</em>.</p> <p>Any thoughts on that? Is this a default CakePHP behavior or is there something I could do to make it work(auto populate)? I have no problem with the jQuery (already tested it in several ways), <strong>the real problem is into getting this field populated back after form submission</strong>. Any help is much appreciated.</p>
 

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