No announcement yet.

Form sending Emails

  • Filter
  • Time
  • Show
Clear All
new posts

  • Form sending Emails

    This isn't as much a problem as it is a procedural thing.

    I have a form to be filled out. When complete, the submit button should send an email and write the form data to a table.

    Currently I have the code placed in Events, in the OnBeforeInsert. The reason for this was when I did the email OnAfterInsert, any quotes/apostrophes the user entered into the notes field, would end up with "/" characters in the email body. I found if I did it OnBeforeInsert, the text was sent clean, just like it was typed in. All has been working fine, until last night......

    An email was received from a new submission, but the data was not in the table.... So clearly something happened in the split second between the script sending the email (successfully) and writing to the table (unsuccessfully)...and I'm not sure of the best way to figure out what happened, so that I can fix it.

    This morning I built a test version of the same form....with OnAfterInsert, and instead of grabbing the {fields} and putting them in the email immediately, I instead grab the ID for the new record {ID}, make it a global variable [tmpID]={ID}, and then run a query to pull in the fields of that [tmpID] into the email from the table....which works fine too, and actually doesn't break the formatting of apostrophes e.t.c.

    What is the "best" way to do this? The test version works well, but if it's failing to write to the table, then we're still going to have an issue. Is there specific code I can add into the form to notify the user if the table write fails? I am using Version 8.00.0043.

    Thanks very much in advance.

  • #2
    I would do it on the OnAfterInsert since the point that the insert then has been done. The issue with the quotes ending up with / is another issue.
    The question is whether your fields have that slash in there is kind of new to me. Then again I virtually never use OnAfterInsert
    Anyway your getting the data from the table is the smart way of doing it since you then get the exact data that you want. Scriptcase does some conversions (if needed) between character sets when it saves the data. I rather prefer OnValidateSuccess or OnValidate.


    • #3
      Thanks rr, learning from scratch sometimes has it's disadvantages.....when you suddenly wonder if your understanding of a process has always been completely off base! <grin> I will change the form to OnAfterInsert, and then have a query pull the data from the table as an extra step, verse relying on the form {fields} being populated in the email. I appreciate the direction and hope you have a great weekend!