You are viewing limited content. For full access, please sign in.

Question

Question

dynamic hyperlinks in forms email

asked on March 24, 2022 • Show version history

I'm trying to send an email from a form with a set of links based on checkboxes on the form.

In the case below, they would get only the one link that matches their corresponding check box. 

I am able to create the links in the Rich Text field. (thanks to answers I received here: https://answers.laserfiche.com/questions/196882/updating-rich-text-using-JavaScript#196890 )

However when it gets to the email it looks like the following. 

When I inspect the email it shows that it changed < to &lt; and changed  > to &gt;

What I'm ultimately wanting to do is, generate the body of an e-mail that will be sent to external e-mail addresses with the URLs needed to launch the selected forms.

So what I'm asking is there a way to fix this so It does not change the < and > or is there a better way to approach this task? 

 

 

2 0

Answer

SELECTED ANSWER
replied on March 24, 2022

This is the code that is working. 

 

  function addLinkElement (formName, formText) {
    
    /* Create an anchor element */
    var theAnchor = document.createElement("a");
    
    /* Create the text node for anchor element */
    var theText = document.createTextNode(formText);
    
    /* Append the text node to anchor element */
    theAnchor.appendChild(theText); 
    
    //theAnchor.id = 'emailLinks';
    theAnchor.id = formName;
    
    /* set the title */
    theAnchor.title = '' + formText;
    
    /* set the href property */
    theAnchor.href = "https://OUR-Website-HERE/Forms/"+formName+'?Reference_ID={/dataset/_instance_id}';
    
    /* add the ancher and break to the rich text editor */
    $('.emailFormatted .rich-text-editor').append(theAnchor);
    $('.emailFormatted .rich-text-editor').append('<br id="'+formName +'BR">'); 
   
  };
  
  
  function formatEmail()
  {
    
    /* Loop through the checkbox list */
    $('.formsCheckboxes .choice').each(function() {     
      var isChecked = $(this).find('input[type=Checkbox]').is(':checked');
      var theValue = $(this).find('input').val();
      var theLabel = $(this).find('label').text();
      if(isChecked)
      {
        addLinkElement (theValue, theLabel);               
      };
    });
    
  };/* END:  function formatEmail()*/
  
  function clearOldAnchors()
  {        
    
    /* Loop through the checkbox list to get the IDs for removal*/
    $('.formsCheckboxes .choice').each(function() {     
      
      var theID = $(this).find('input').val();
      $('#'+theID).remove();
      $('#'+theID+'BR').remove();
      
    });
 
  }; /* END: clearOldAnchors() */
    

  $('.formsCheckboxes input').change(function () {
    clearOldAnchors();
    formatEmail()    
  });
  
  /* on load */
  formatEmail ();  

 

2 0

Replies

replied on March 24, 2022

I may have found something that works .. first quick test using just hardcoded values seems to work. 

 

  function addLinkElement () {
    
    /* Create an anchor element */
    var theAnchor = document.createElement("a");
    
    /* Create the text node for anchor element */
    var theText = document.createTextNode("This is a link");
    
    /* Append the text node to anchor element */
    theAnchor.appendChild(theText); 
    
    /* set the title */
    theAnchor.title = "This is a link";
    
    /* set the href property */
    theAnchor.href = "https://www.geeksforgeeks.org";
    
    $('.emailFormatted .rich-text-editor').append(theAnchor);
    
  };

 

1 0
SELECTED ANSWER
replied on March 24, 2022

This is the code that is working. 

 

  function addLinkElement (formName, formText) {
    
    /* Create an anchor element */
    var theAnchor = document.createElement("a");
    
    /* Create the text node for anchor element */
    var theText = document.createTextNode(formText);
    
    /* Append the text node to anchor element */
    theAnchor.appendChild(theText); 
    
    //theAnchor.id = 'emailLinks';
    theAnchor.id = formName;
    
    /* set the title */
    theAnchor.title = '' + formText;
    
    /* set the href property */
    theAnchor.href = "https://OUR-Website-HERE/Forms/"+formName+'?Reference_ID={/dataset/_instance_id}';
    
    /* add the ancher and break to the rich text editor */
    $('.emailFormatted .rich-text-editor').append(theAnchor);
    $('.emailFormatted .rich-text-editor').append('<br id="'+formName +'BR">'); 
   
  };
  
  
  function formatEmail()
  {
    
    /* Loop through the checkbox list */
    $('.formsCheckboxes .choice').each(function() {     
      var isChecked = $(this).find('input[type=Checkbox]').is(':checked');
      var theValue = $(this).find('input').val();
      var theLabel = $(this).find('label').text();
      if(isChecked)
      {
        addLinkElement (theValue, theLabel);               
      };
    });
    
  };/* END:  function formatEmail()*/
  
  function clearOldAnchors()
  {        
    
    /* Loop through the checkbox list to get the IDs for removal*/
    $('.formsCheckboxes .choice').each(function() {     
      
      var theID = $(this).find('input').val();
      $('#'+theID).remove();
      $('#'+theID+'BR').remove();
      
    });
 
  }; /* END: clearOldAnchors() */
    

  $('.formsCheckboxes input').change(function () {
    clearOldAnchors();
    formatEmail()    
  });
  
  /* on load */
  formatEmail ();  

 

2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.