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.

custom queries in notification message

  1. Mexx


    I have a gravityform for my users to order voucher codes with. I store the voucher codes in a separate table of my wordpress DB. When a user submits the form, there should be an email immediately send to them with a code in it. I could use another plugin for that or write an own solution, but then the form does not feel, look and behave the same way other forms on my website do. Also the form data does not get stores in Gravaty's statistic.

    I tried to put a SQL query in the message box of "Notification to User". But this code is not executed and just printed out:

         $sq = "SELECT code FROM vouchers WHERE used<>'yes' LIMIT 1";
         $query = mysql_query($sq);
         $dsatz = mysql_fetch_assoc($query);
         echo $dsatz['code'];

    I tried to find and hack the place in the plugin files where this codes gets escaped. Couldn't find it.
    Can you point me to that place and give me a hint how to archive that?

    thanks, Max

    Posted 11 years ago on Tuesday July 20, 2010 | Permalink
  2. The Notification to User message body won't support a query or PHP code.

    Probably the easiest way to accomplish this would be to use a hidden field in your form that would represent the voucher code. Then use a PHP hook to populate that hidden field with the voucher code that you query from your custom table when the form is submitted.

    Then in your notification email you can just output the value of that hidden form field that would contain the voucher code.

    How comfortable are you with PHP and API hooks?

    Posted 11 years ago on Tuesday July 20, 2010 | Permalink
  3. Mexx

    Hi Carl,

    thanks for that very quick respond. That sounds like a good solution.
    I'm quite comfortable with PHP but not with API hooks.

    Its probably some PHP thats resides in the function.php of my theme I guess.
    But I haven't developed a plugin yet and therefore haven't done any WP API stuff.
    I guess I could read a bit through Codex and figure out how to add a hook.
    But then, how do I address that Gravity input field from that hook?

    If you could provide me with some code, that would be nice.

    thanks, Max

    Posted 11 years ago on Tuesday July 20, 2010 | Permalink
  4. Mexx

    Hey Carl,

    can I accomplish this with these hooks?

    thanks, Max

    Posted 11 years ago on Wednesday July 21, 2010 | Permalink
  5. Hey Mex,

    You're probably going to want to use the gform_pre_submission_filter filter. This filter runs after the entry has been validated, but before the entry is saved to the database.

    The form object is passed as an array to this function, but you can modify the entry values as well by adding/updating the $_POST array. This would be an ideal place to query your database for the voucher code and then (building on Carl's suggestion) add a value to the $_POST that corresponds with the id of the hidden field. When the form is saved (and emailed to the user) the field will be populated for you.

    Posted 11 years ago on Friday July 23, 2010 | Permalink