You could use the following as a skeleton for your script. The script both creates the page with the form (subroutine formmaker - the content of which you should replace with your webpage of course) and evaluates the returned parameters, if necessary re-displaying the form with an appropriate message to fill in the email-addres.

Checking whether the email is 'valid' is left as an excercise for the reader. The regex used should not even be considered to be the basis of such test.

use strict; use CGI qw/:standard/; if (param()) { if (param('email')=~/\w+@\w+/) { print header, start_html('Thank you'), h1('Thank you'), p, param('name'), ' now that we have your e-mail address w +e will send lots of nice spam to you at ', param('email'), '!', p; } else { formmaker('You must provide an email address!'); } } else { formmaker(); } sub formmaker { print header, start_html('A Form with Sticky Fields'), h1('A Form with Sticky Fields'), p; my $message = shift; print $message, p if $message; print start_form, "What's your name? ",textfield('name'),p, "What's your email? ",textfield('email'), p, ,p, submit, end_form, hr; }

As you will see when you test this script, the fields are 'sticky', i.e. they keep their values between invocations.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law


In reply to Re: Re: Re: Re: Re: Create required fields from form by CountZero
in thread Create required fields from form by hcb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.