We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Accessing grid field values from within a channel form tag?

How Do I?

JCOGS Design's avatar
JCOGS Design
71 posts
6 years ago
JCOGS Design's avatar JCOGS Design

Is this possible?

I have a simple grid field: two text field columns, seven rows.

I would like to fill in these values using <input> html tags in a simple form.

This should be no more complicated than getting the grid field tag and looping seven times to load up seven pairs on input tags… but it doesn’t seem to work that way.

I have tried all the combinations of guesses based on the (not very helpful) EE documentation for grids in channel forms, but basically whenever I try to I basically get a SQL error.

This issue appears to have come up before without any resolution. As noted above documentation on this is vague too.

Is this possible? If so how? If it is not possible, would value suggestions on other ways I could load up these values.

NB - I’m not trying to put the grid field itself into the form - just want to set the values

Thanks in advance for any help with this.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
6 years ago
Kevin Cupp's avatar Kevin Cupp

I don’t think there is a nice way, Channel Form doesn’t use the same parser as Channel Entries. Plus Grid is a complex fieldtype and it’s not meant to be reproduced in this way, and so the documentation includes all the recommended ways to use Grid in Channel Form, it shouldn’t be lacking. But if you really need to, you could probably use the Query module to do this.

       
JCOGS Design's avatar
JCOGS Design
71 posts
6 years ago
JCOGS Design's avatar JCOGS Design

Hmm. OK Kevin that’s helpful to know.

As for the documentation, unless I am missing a section the entire documentation on how to access grid fields within a channel form comprises this entry:

{custom_fields}
             {grid_field}
{/custom_fields}

and a note to say that ‘manual construction of a grid field’ is not supported - both of which relate I think to placing the editable table view of a grid field in a form.

I can find nothing about how to go about simply revealing or changing the values held within grid variables.

The issue is not so much the revealing (this can be done using layout variables) but rather then setting of the values back to EE. If I understand your observation, the way to do this is to reconstruct the channel entries parser within the SQL in a query tag - which not only seems rather heavy handed, but also goes against the general guidance that EE data should be changed via the EE data model system rather than via hacks into the SQL.

Perhaps you could suggest a reliable way to craft the SQL call for updating grid field values in the way you suggest?

Thanks.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
6 years ago
Kevin Cupp's avatar Kevin Cupp
unless I am missing a section the entire documentation on how to access grid fields within a channel form comprises this entry:

Yes there’s also the {field: syntax section below that.

and a note to say that ‘manual construction of a grid field’ is not supported - both of which relate I think to placing the editable table view of a grid field in a form.

Manual construction refers to what you are trying to do, it’s not dependent on being in a table, it just means reconstructing the basic form inputs without letting EE render them.

I can find nothing about how to go about simply revealing or changing the values held within grid variables.

Yes, like I said, the parser won’t reveal the values, and like you mentioned, manually constructing the form isn’t supported. This is why it is not in the documentation.

If I understand your observation, the way to do this is to reconstruct the channel entries parser within the SQL in a query tag - which not only seems rather heavy handed, but also goes against the general guidance that EE data should be changed via the EE data model system rather than via hacks into the SQL. Perhaps you could suggest a reliable way to craft the SQL call for updating grid field values in the way you suggest?

No, my suggestion was to do with displaying the values, not updating them. It’s a simple SELECT query to get the data, and the Query module won’t let you do anything other than a SELECT. If you need to also update the values, the best way currently is to reconstruct the form, which some have written about. That way, it’ll go through the proper routes on its way in.

       
JCOGS Design's avatar
JCOGS Design
71 posts
6 years ago
JCOGS Design's avatar JCOGS Design

Hi Kevin

I saw the note about ‘manual construction of a grid field’ is not supported (and noted it in my reply earlier).

I had seen the caffeinecreations.ca article too (along with another one also): I’ll give that sort of thing a try.

In the interim I’ve put in an ugly work-around that uses achannel:entries tag to expose the values to a standard HTML form, and then an “unrestricted” version of exp:query to issue an update SQL command addressing the specific fields based on form content. Which works, but I feel for something as useful as the Grid field mechanism should not be necessary.

Fingers crossed that one day channel:form will more closely mirror channel:entries for function.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
6 years ago
Kevin Cupp's avatar Kevin Cupp
I saw the note about ‘manual construction of a grid field’ is not supported (and noted it in my reply earlier).

Yes and I acknowledged that in my reply as well.

Fingers crossed that one day channel:form will more closely mirror channel:entries for function.

Maybe, I would instead hope for Channel Form to be able to render individual inputs inside of a Grid. Otherwise, if all you had access to were the values, you’d still be stuck manually hard-coding and fiddling with form input names. Seems nicer if you could just do something like {grid_field:text_field:input}, kind of like Freeform.

       
JCOGS Design's avatar
JCOGS Design
71 posts
6 years ago
JCOGS Design's avatar JCOGS Design
Seems nicer if you could just do something like {grid_field:text_field:input}, kind of like Freeform.

Agreed. Would be a great improvement - fingers crossed!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.