Say you have a submission process that requires two forms. The submission of the 2nd form triggers an email. What do you do if the second form isn't submitted? Say the user forgets or closes the window by accident.

My only solution was to update the DB with a flag from the submission of the 1st form that identifies an email has not been sent. Submission of the 2nd form will trigger an event to send an email and update the DB with a flag that identifies an email has been sent. A cron job will run periodically to check for any flags for unsent emails, gather the information, and send an email.

Is this the best way of dealing with the issue?


Edit: Clarity

Form 1 User submits general data

Message 1 User presented with a choice. User needs to choose to "pass" or "accept". If the user submits the "accept" form (Form 2), an email is sent. If the user submits the "pass" form (Form 2), they are presented with another message with another choice (Form 3). If the user does nothing, the last choice provided is their default choice, but at this point an email still needs to sent.

I hope that's more clear.

3 Answers 3


It depends on why you are concerned about this.

If your concern is about having incomplete data in you DB I'd suggest just keeping the entered data in the user session until the user completes the second form and then update the DB and send the e-mail. If the user doesn't bother to fill out the second form, then the entire exchange will be forgotten once his session times out.

If your concern is about users failing to realize that they need to complete the second form you should strongly consider redesigning the forms (possibly merging them). This is a user interface issue.

Having a flag (as discussed in question) could help identify if this happens, but it wont tell you if it is happening through user error or simply because the user lost interest (unless you have a captive audience of some sort).

An alternative, if you can hook into when a user's session expires (this is fairly simple with Java sites, I'm not familiar with this feature in other server side technologies) you could check for incomplete transactions at that point.

  • Thanks. The second form (regardless if it is submitted or not) will default to certain values. Technically, the user doesn't need to submit the second form at all. So I understand the concern you're implying regarding incomplete data, but the only issue of concern for me is the failure to send the email.
    – user334
    Jul 15, 2010 at 23:17
  • @peopleofpublictransit.wordpress.c Sounds like an interface problem then. I'd reconsider the workflow.
    – Kris
    Jul 15, 2010 at 23:37

Since HTTP is stateless, the only way to track whether a user has submitted the first form once the browser is closed is by using a persistence mechanism (e.g., a database) just as you have done.

However, you may run into a problem if users submit the first form and the cron job runs before they have a chance to submit the second form. You may want to also check that a certain amount of time has also passed.

Theoretically you could also try to detect when the browser is closing and use that event to trigger an action, but I advise strongly against it.

  • Thanks, I didn't think about the possible cron conflict. I do keep track of the DB entry times, so I'll just ensure, as you said, enough time has passed. I also wanted to avoid client side triggers. Thanks again.
    – user334
    Jul 15, 2010 at 21:14

AS you describe, you should have a state of the process in your database to identify which steps have been completed..

Now, the next step depends on the technology used..

For ASP / ASP.NET there is an event triggered (server-side) when the session expires, and catching it you can perform the clean-up/auto-completion of the procedure..

Not sure if this is possible in PHP environments though .. i suppose you could store a timestamp once the 1st step is completed and a cron job will periodically run but first check against the timestamp to see if a set amount of time has passed before auto-completing ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.