5

I need to use SafeCracker to publish a new entry into a Channel whose Custom-Field-Group exists of only one field — which is a quite large Matrix-field. (Matrix -> pixel&tonic Fieldtype)

The code look like this (but with much more fields)

{exp:safecracker channel='mychannel' return='success' include_jquery='no' datepicker='no'
…
<input type="hidden" name="title" class="title" value="" />
<input type="hidden" name="mychannel-field0" class="field0" value="" />
…
{/exp:safecracker}

The fields will get filled through a JavaScript-Datafetcher.

My Matrix-Field is named {mychannel-entry} and the first cell is named mychannel-field0 etc.

How can I tell my form to input the values of my hidden fields into the first/new Row-Cells of a new entry to my channel?

Note: This form only adds new entries, no editing-functions required.

| improve this question | | | | |
6

So I haven't been able to test this, but you should be able to just manually build your form like so:

{exp:safecracker channel='mychannel' return='success' include_jquery='no' datepicker='no'}
  <input type="hidden" name="mychannel-entry[row_order][]" value="row_new_0" />
  <input type="text" name="mychannel-entry[row_new_0][col_id_1]" />
  <input type="text" name="mychannel-entry[row_new_0][col_id_2]" />
  <input type="text" name="mychannel-entry[row_new_0][col_id_]" />
{exp:safecracker}

I've assumed above that your full column name in your matrix settings is mychannel-fieldn. Is that correct? Edit, the previous, struck through line was incorrect.

Where col_id_n is the column_id of the column in your matrix field - nb this is not the same as the column name - use firebug/dev tools to figure this out as suggested in the blog post linked in the other answer to this qn.

NB. Taken from a similar question in P&T's support forum.

| improve this answer | | | | |
  • THX! this works! – albuvee Nov 22 '12 at 9:14
6

I've done this before - I spoke with Marcus Neto about it and sent him the code for it which he blogged about here

This should give you enough information to do what you need I think.

| improve this answer | | | | |
  • thx for the reference to the blog-post! that's a nice reference incl. the «add»- and «remove»-functionality! THX! Since Tom was 3 Minutes faster, I have to give him the «Accept Answer» — I hope you don't mind ;-) – albuvee Nov 22 '12 at 9:13
  • Interesting why you'd give him the accept answer considering it doesn't actually answer your question and he just references my post - but it's entirely up to you! :) – madebyhippo Nov 22 '12 at 9:19
  • @madebyhippo I think it does precisely answer the OPs question - I actually got my answer from the P&T support forum post I linked to, then referenced the (different) post you linked (with credit) to correct an error I made when generalising from the P&T post to the OP's use case. You essentially posted the same answer but as a link to a different external resource a few minutes after my original post - I wasn't trying to "jump" your answer, just wanted to provide the most correct info on this site that I could. – Tom Davies Nov 22 '12 at 10:22
  • @madebyhippo have clarified my previous edit. if that makes sense. Meta! – Tom Davies Nov 22 '12 at 10:24
  • Thanks for that link Carl! That was exactly what I needed! – Marc Miller Feb 1 '13 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.