PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Submitting form with custom hidden field

  1. Tristan
    Member

    Please point me in the right direction if this has already been addressed. I did a few searched but couldn't find anything.

    I'm wondering how I might go about appending a hidden field to a form submission?

    I have certain forms that will be submitted by logged in users and I want to append their username and the name of the Page their on to the form, but make this invisible on the form.

    Any pointers?

    Posted 13 years ago on Thursday July 14, 2011 | Permalink
  2. That information is already captured by Gravity Forms. Assuming you want it send in the admin email notification, you can just add these two fields to your notification:

    {user:user_login}
    {embed_url}

    along with whatever else you want sent in the notification. If you want to do something else with the information, please post your use case and we'll help you out.

    Posted 13 years ago on Thursday July 14, 2011 | Permalink
  3. Tristan
    Member

    Hey Chris,

    Thanks for your reply. I should have provided the full picture of what I'm trying to achieve.

    Basically, I want my users to report statistics every week and I want those statistics tied to individual users. I want to then show the previous week/month/year statistics on a chart so I need these statistics to go into a database.

    That's why I need some way of including a username so that I can query the database using a WHERE statement to select only the statistics tied to a particular user. I also need to link the statistics to a particular action, thus my requirement to submit the name of the page.

    Posted 13 years ago on Friday July 15, 2011 | Permalink
  4. Like Chris said, you can use the {user:user_login} fields anywhere in the form definition.

    I have a similar situation where I included that in the form submission itself:

    1. created a hidden field in the form
    2. set its default value to {user:user_login}

    So, for logged in users, that hidden field will contain his username. For guest users, that field will be empty, so it won't even exist in the lead details db table.

    Your db query would therefore be something like this (with example filter.* values):

    select entry.id, entry.lead_id, entry.field_number, entry.value
    from wp_rg_lead_detail entry
    left join wp_rg_lead_detail filter on filter.lead_id = entry.lead_id
    where filter.form_id = 1
      and filter.field_number = 1
      and filter.value like '%username%'
    order by entry.lead_id, entry.field_number;
    Posted 13 years ago on Friday July 15, 2011 | Permalink
  5. Tristan
    Member

    Hey Hugo,

    Thanks for the code. Looking at the database structure i've realised that it probably won't suit me. I need all the relevant data in a row, not in separate rows as GF does things by default.

    I would need to be able to get data for all fields based on the user_login or the page_url, but pertaining to a particular date. Hmmm, come to think of it, maybe it is possible, although rows seems like it would make things easier.

    Hmmm. At least I know where to go from here to keep working on the idea.

    Thanks all.

    Posted 13 years ago on Sunday July 17, 2011 | Permalink