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.

User notifications with fields containing html tags

  1. Hi!

    My form needs to generate a number of unique coupon codes depending on the product quantity. Then, the coupons are emailed to the user as absolute links for him to print or share.

    I have managed to populate a paragraph text field using gform_pre_submission to hold the coupon codes in absolute links. However, in order to have my < a > tags register as entries, I used htmlentities() on every string:

    foreach ($qte_array as $coupon) {
    
        	$s = strtoupper(md5(uniqid(rand(),true)));
    
    		$string = $coupon . '-' . substr($s,0,6) . '-' . substr($s,8,4);
    
    		$eachcoupon[] = $string;
    
    		$url_string = "<a href=\"http://www.domain.com/coupon.php?offre=" . $id . "&achat=" . $achat . "&coupon=" . $string . "\" target=\"_blank\">Coupon " . $coupon . "</a><br />";
    
    		$eachcouponurl[] = htmlentities($url_string);
    
    	}

    Now the problem is that when I email this paragraph text field, it's not HTML anymore... :-(

    Is there a way to run some sort of html_entity_decode() to my entry, or did I take this the wrong way?

    Posted 13 years ago on Friday June 17, 2011 | Permalink
  2. I have forwarded this post to our lead developer who will take a look and get back with you sometime tomorrow (Friday).

    Posted 13 years ago on Friday June 17, 2011 | Permalink
  3. Thank you Carl,
    I can post more code or information if needed :)

    Posted 13 years ago on Friday June 17, 2011 | Permalink
  4. Do you need to store these with the entry, or do you just need to send them out in the email?

    Posted 13 years ago on Friday June 17, 2011 | Permalink
  5. Ultimately, I don't need to store these coupon links with the entry, just the coupon codes. The latter works just fine with a paragraph text field populated without formatting ($eachcoupon[]).

    Right now I have this other paragraph field holding the same coupons as absolute links ($eachcouponurl[]), as I couldn't figure out another way of inserting them in the email notifications.

    If there was a single field for every coupon, formatting the email would be really easy from the notifications panel. The problem really comes when having to generate a varying number of coupons codes...

    Posted 13 years ago on Friday June 17, 2011 | Permalink
  6. I thought of a way to trick the system.
    Use the post body field (which allows HTML) instead of a regular paragraph field. Then use a hook to disable the post creation. Make sure to remove the htmlentities() from your code.
    Disable the post creation with the following code snippet. Make sure to replace "5" below with your actual form ID.

    add_filter("gform_disable_post_creation_5", "disable_post_creation", 10, 3);
    function disable_post_creation($is_disabled, $form, $entry){
        return true;
    }
    Posted 13 years ago on Friday June 17, 2011 | Permalink
  7. That worked like a charm!

    Posted 13 years ago on Friday June 17, 2011 | Permalink