Limit FORM mailer submissions to 5 on website, then pause until reviewed by webmaster

Discussion in 'Perl Misc' started by Lance, Sep 27, 2006.

  1. Lance

    Lance Guest

    Hi everyone,

    I was hoping someone could help or point me in the right direction.

    I would like to install an intelligent Form mailer on my up and coming
    website.
    The purpose of the Form mailer will be to either submit to a database
    or send an email. However, I would like the form mailer to pause and
    prevent any further submissions after 5 submits. During this period new
    users visiting the page should automatically be redirect to another URL
    displaying a message similar to '5 forms have already been submitted,
    please check back soon'. Once I have reviewed the 5 submitted forms,
    I should then be allowed to open the form up again.

    Looking forward to your suggestions.

    Many thanks,

    Lance

    P.S - my scripting knowledge is very limited ;-)
     
    Lance, Sep 27, 2006
    #1
    1. Advertising

  2. Lance

    Matt Garrish Guest

    Lance wrote:

    > Hi everyone,
    >
    > I was hoping someone could help or point me in the right direction.
    >
    > I would like to install an intelligent Form mailer on my up and coming
    > website.
    > The purpose of the Form mailer will be to either submit to a database
    > or send an email. However, I would like the form mailer to pause and
    > prevent any further submissions after 5 submits. During this period new
    > users visiting the page should automatically be redirect to another URL
    > displaying a message similar to '5 forms have already been submitted,
    > please check back soon'. Once I have reviewed the 5 submitted forms,
    > I should then be allowed to open the form up again.
    >


    [realizing this has absolutely nothing to do with Perl...]

    Your requirements are a bit vague, but I'm assuming all submissions go
    into the database and the email goes out when you confirm the
    submissions? If that is the case, the standard approach is to add a
    confirmation column to your table. You can then count the number of
    unconfirmed entries before displaying the page and if it already equals
    five display your alternate text. You just have to bear in mind that
    multiple people could see the form while it still only registers 4
    submissions, and they could all try to submit to be the fifth, which
    might make some users unhappy when they find out they're actually
    number 6,7,8,9... and rejected after filling out the form. It also
    means that as you confirm the entries new ones will be able to go in.

    If you don't want to be counting all the time from your database, there
    are other options but they require a good deal of care to implement.
    One would be to create a separate table with just the current count and
    check it each time (but you'll need to properly lock the tables during
    transactions to ensure accuracy). Another would be to use a text file
    for the count, holding a lock on it while the database update occurs
    and then wrting the new count. You can then review the five submitted
    entries at your leisure but until you reset the count table/text file
    no one can submit (i.e., your database won't keep filling up as you
    review).

    With a limit of 5 it doesn't sound like you're dealing with enough
    traffic that you'd need to worry yourself about the latter options,
    though.

    To give this some Perl content, there are many modules available that
    make writing a script like you've described very simple. For databases,
    have a look at DBI (and probably DBD::MySQL), and for sending emails
    there's Net::SMTP, Mail::Mailer, etc.

    Just don't post back asking someone here to write it for you, unless
    you enjoy being flamed...

    Matt
     
    Matt Garrish, Sep 27, 2006
    #2
    1. Advertising

  3. Lance

    Lance Guest

    Thank you Matt.

    Your response and suggestions were amazing and well detailed. It's
    given me a lot more to think about and definitely helped me to see the
    bigger picture and protection problems.

    Although i may not get a large number of posts simultaneously, i will
    need to think about either counting the current sessions or applying a
    lock on a file, as the type of posts could mean that users spend 30
    minutes writing the post before clicking submit. It sounds easier to
    have a script that creates a temporary row in a sessions table as soon
    as the Form Windows is opened. I would need to include a script just
    before that to do a count on the session table. If the count is >= 5,
    then don't display the input form and instead display the message,
    otherwise show the form.

    So to avoid being flamed, could I ask if anyone could recommend a good
    place to start and the best programming language to go with? I'll be
    very grateful for any links and additional pointers.

    Many thanks again Matt for your post..

    Lance
     
    Lance, Sep 28, 2006
    #3
  4. Lance

    Matt Garrish Guest

    Lance wrote:

    > Thank you Matt.
    >
    > Your response and suggestions were amazing and well detailed. It's
    > given me a lot more to think about and definitely helped me to see the
    > bigger picture and protection problems.
    >


    Happy to help, but please quote context when you reply.

    > Although i may not get a large number of posts simultaneously, i will
    > need to think about either counting the current sessions or applying a
    > lock on a file, as the type of posts could mean that users spend 30
    > minutes writing the post before clicking submit. It sounds easier to
    > have a script that creates a temporary row in a sessions table as soon
    > as the Form Windows is opened. I would need to include a script just
    > before that to do a count on the session table. If the count is >= 5,
    > then don't display the input form and instead display the message,
    > otherwise show the form.
    >


    You wouldn't lock the file from the time they come to the page until
    the time they submit. That would make your application impossible to
    use. All I meant is that the file is locked while the transaction to
    the database occurs (fraction of a second), so that no other attempts
    to submit can happen while that one is in progress. The same can be
    done by writing a proper transaction when you submit to your database
    so that the table(s) are locked while that update occurs.

    I think you have too much faith in the statefulness of web
    applications, though. It's a bad idea to try and stop submissions when
    you think you might have reached your limit. What if the person loads
    the page and then goes away? What if they fill out some of the form and
    go away? You'd then need a way to (somewhat arbitrarily) reap the
    unused locks you've written to your database, which is an ugly
    approach.

    There's no nice way to do what you're after, other than to check your
    count however you implement it both before displaying and before
    accepting (don't forget a spammer who gets the source for your form can
    bypass the first count). And that means that some people may get
    rejected. It's just a fact of life if you're going to impose a limit
    like you want.

    > So to avoid being flamed, could I ask if anyone could recommend a good
    > place to start and the best programming language to go with? I'll be
    > very grateful for any links and additional pointers.
    >


    Yes, Perl, but that's what you get for asking in a Perl newsgroup. I
    doubt that you'll find anything prewritten, because these kinds of
    multi-faceted applications tend to be use-specific, so there's no good
    way to abstract them into something that anyone could plug in. If
    you're looking to write it yourself, you might want to start at
    learn.perl.org, otherwise you could look for someone to freelance at
    jobs.perl.org.

    Matt
     
    Matt Garrish, Sep 29, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrzej Adam Filip
    Replies:
    0
    Views:
    4,214
    Andrzej Adam Filip
    Mar 31, 2008
  2. Replies:
    0
    Views:
    341
  3. Replies:
    0
    Views:
    226
  4. Replies:
    0
    Views:
    551
  5. Tuxedo
    Replies:
    7
    Views:
    440
    J. Gleixner
    Aug 16, 2012
Loading...

Share This Page