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.

Insert Entries via PHP / MySQL

  1. Is there a function or best-practice code used by people in the know on how to use PHP to insert an entry for a form? Or is it just something someone would need to run a MySQL INSERT query for?

    Posted 10 years ago on Thursday February 3, 2011 | Permalink
  2. I'm not aware of any help functions, but i'd have to talk to Alex to see if any exist. My guess is there currently is not. So a manual insert query would have to be used, and very carefully so the data is inserted correctly.

    I can talk to him about adding a helper function that could be used to insert entries... we are planning on creating import entry functionality eventually so some sort of function would probably be created for this.

    Our plan for the import entry functionality was to be able to upload a CSV file and then allow the user to map the contents of the CSV to the available form fields and then running the import.

    Posted 10 years ago on Friday February 4, 2011 | Permalink
  3. Any updates on this, or is manual MySQL insertion still required? I'm trying to populate the GF backend with data from a non-GF form, and I was hoping to find something in the GF API to expedite the process.

    If not, do you have any advice for proceeding? Any pitfalls I should be aware of?

    Thanks a lot; you guys are consistently great at providing support.

    Posted 10 years ago on Tuesday November 1, 2011 | Permalink
  4. Unfortunately we don't have an API to insert entries. The function we have to create entries, look for values in the $_POST variable and won't be useful when batch importing entries. Importing entries is a feature that is commonly requested and it is something we will definitely implement in the near future. Until then, you will need to manually insert the records using MySQL. The process should be the following:
    1- Insert into wp_rg_lead and read the newly inserted ID.
    2- Insert a record into wp_rg_lead_detail for each field of your form. The lead_id column corresponds to the ID inserted in step 1 and the field_number column corresponds to the Field ID. If the field value has more than 200 characters, insert the first 200 characters in this table. The full text will be inserted in step 3
    3- If the field value from step 2 is larger than 200 characters, insert the full value into the wp_lead_detail_long table.
    4- If you have any notes, insert them into the wp_rg_lead_notes

    Good luck and let us know if you having problems with it.

    Posted 10 years ago on Wednesday November 2, 2011 | Permalink
  5. What I'm really looking to do is to pull information from a custom form on my site (not a GravityForm, something completely bespoke with better control over semantics) into the GF backend. I'd love to be able to use my own forms on the frontend, but have the entry-sorting capabilities of the GF admin area. Does that make sense?

    Posted 10 years ago on Thursday November 3, 2011 | Permalink
  6. cacmember
    Member

    Awesome post, Alex. Your instructions are clear and workable. I was able to inject a reverse engineered .csv record up into a GFs mySQL database (at CaliforniaAlpineClub.org). I have about 600 records to go, so my next approach is to see how I can automated the solution. Any suggestions you might have would be greatly appreciated.

    Thanks Again.

    Posted 9 years ago on Sunday April 1, 2012 | Permalink
  7. nitasmith
    Member

    Thanks Alex. Helped tremendously!

    Posted 9 years ago on Tuesday October 9, 2012 | Permalink