Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With concrete5 blocks, there are two different situations you could be in:</p> <ol> <li>admin user is editing the block (or adding a new block), and you want to save this data to the database.</li> <li>public user is viewing the block, but the block view itself has a form (for example, a contact form block) and you want to do something when the public form is submitted (for example, send a notification email to an admin that someone has filled out the form, or store the submission in a database for future review).</li> </ol> <p>If you're talking about situation #1, you need to put some custom code in the controller's <code>save()</code> method. If you're talking about situation #2, you need to create your own action method in the controller, AND you need to actually have a <code>&lt;form&gt;</code> in the view.php file.</p> <p>UPDATE: Based on the sample code you added to your question, here is the solution: The only way your data can get back to the server is via a form POST. <code>&lt;li&gt;</code> elements are not form fields, and hence the data in them doesn't get POST'ed with the form. So when you add the new <code>&lt;li&gt;</code> element to the page, you should <em>also</em> add a hidden form field, like so:</p> <pre><code> var listItemCounter = 0; $("#addList").click(function() { listItemCounter++; var text = $("#inputList").val() + '&lt;button data-id="' + listItemCounter + '"&gt;x&lt;/button&gt;'; //assign a unique id number to this button, so it knows which hidden field to remove when clicked if(text.length){ $('&lt;li /&gt;', {html: text}).appendTo('ul.featureList'); $('&lt;input type="hidden" name="features[]" value="' + text + '" data-id="' + listItemCounter + '" /&gt;').insertAfter('ul.featureList'); }; }); $('ul').on('click','button', function(el){ $('input[data-id="' + $(this).attr('data-id') + '"]').remove(); //remove the hidden field so it does not get POSTed when user saves $(this).parent().remove(); }); </code></pre> <p>Now, in your block's controller.php file, you will want to add a <code>save()</code> method that will take all of the data from those hidden fields, combine them and put them into the "features" field that you declared in your db.xml file:</p> <pre><code>public function save($args) { $args['features'] = implode("\n", $args['features']); //combine all feature items into one string, separated by "newline" characters parent::save($args); } </code></pre> <p>Finally, in your view.php file, you can convert the list of features (which was saved to the database as one string, with each item separated by a "newline" character) like so:</p> <pre><code>&lt;?php echo nl2br($features); ?&gt; </code></pre> <p>Or if you want to output it as separate list items, you could do something like this:</p> <pre><code>&lt;ul&gt; &lt;?php $features = explode("\n", $features); foreach ($features as $feature) { echo '&lt;li&gt;' . $feature . '&lt;/li&gt;'; } ?&gt; &lt;/ul&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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