Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello All, I have created a web form that uses CGI to process/format the data to send in the background. With the help of some the Perl monks on this site I was able to get the form to send emails out based on Checkbox selection. Is there a way to also send out the email also based on text input. Let say I want to add an additional field call 'Optional email', this will be a text input, the user, if they want to send out addional emails to a user not part of the pre-defined checkbox field, they can manually type in the SMTP address and the form will parse or send it along with the selected checkbox... I don't know if this will work, but I know there's a way to do this. I was able to get this to work with the email (checkbox) selection, so what an addional input field.. Please help...thanks in advanced.

Below is a sample of some of the fields in my form.

SMTP group 1 : checkbox (this will send out to SMTP address if selecgted)
SMTP group 2: checkbox (this will send out if selected)
SMTP group 3: checkbox (this will send out if selected)
Optional Email to sendout: < input field > - this is what I want to add, if a user puts in an additonal SMTP address, this form will also send it to that address, along with the selected checkboxes....

if($in{'ChkboxName1'}){ $in{'form-to'} .= ',EmailGroup1@Domain.com'; } if($in{'ChkboxName1'}){ $in{'form-to'} .= ',EmailGroup2@Domain.com'; } if($in{'ChkboxName1'}){ $in{'form-to'} .= ',EmailGroup3@Domain.com'; } $in{'form-to'} =~ s/^,//;

Replies are listed 'Best First'.
Re: CGI / Perl form to email from input field.
by Tomte (Priest) on Jun 19, 2003 at 22:10 UTC

    This isn't going to be very helpful, feel free to mod me down:

    You don't seem to understand what you're doing, at least this is what your previous question and this one are telling me. Before you settle down to put cgi-code out in the wild, you should undertake the effort of studying the subject a wee bit and to gain some insight into the matter.

    I suggest reading Ovids cgi-course, do a bit of Super Searching, scan the Tutorials and google (offsite). A very good source of solutions with explanations to specific problems is merlyns collection of columns (offsite).

    To clarify my rant: I don't think you're stupid or some such, I just see that a very, very simple problem in cgi-programming puts you off, without even an idea of a possible solution presented in the question, so don't take this as an insult but a more or less humble advice from someone who allmost always found a solution by reading things generously offered by gentle people, sharing there knowledge for a thank you or nothing.

    A good book on programming and/or web-programming won't hurt, though.

    kind regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

Re: CGI / Perl form to email from input field.
by waswas-fng (Curate) on Jun 19, 2003 at 22:15 UTC
    modifying Re: CGI/PERL email form that will send to multiple address based on checkbox selection (lnl's) style you could do this:
    $in{'form-to'} .= $in{'inputf1'} if $in{'inputf1'};
    before the fisrt if($in{'ChkboxName1'}){ or if you ended up using chromatic's code you could do this:
    my @mail_groups = $q->param( 'mailgroup' ); my %group_addresses = ( group1 => 'group1@domain.com', group2 => 'group2@domain.com', group3 => 'group3@domain.com', ); my @mail_addresses = @group_addresses{ @mail_groups }; push @mail_addesses, $q->param('inputf-emailaddr') if $q->param('inpu +tf-emailaddr'); my $to = join(', ', grep { defined } @mail_addresses );
    LOL I can guess what the next question is too: Hello All, I have created a web form that uses CGI to process/format the data to send in the background. Now that I have written the code to collect the email addresses to email to I need to figure out what to do to send the emails... see code below:
    $in{'form-to'} .= $in{'inputf1'} if $in{'inputf1'}; if($in{'ChkboxName1'}){ $in{'form-to'} .= ',EmailGroup1@Domain.com'; } if($in{'ChkboxName1'}){ $in{'form-to'} .= ',EmailGroup2@Domain.com'; } if($in{'ChkboxName1'}){ $in{'form-to'} .= ',EmailGroup3@Domain.com'; } $in{'form-to'} =~ s/^,//;
    =))

    -Waswas
Re: CGI / Perl form to email from input field.
by dash2 (Hermit) on Jun 20, 2003 at 00:19 UTC
    The normal way to get data from HTML forms is to use the standard CGI module.

    use CGI 'param'; # use the CGI module, and import the function named " +param" $email_to = param('extra_emails'); # this assumes that your text input + is called "extra_emails"

    For simplicity, you could use the "param" method for your checkboxes too. Don't do all those ifs though. Use a hash, it's simpler:

    my %checkboxes = ( ChkBoxName1 => 'EmailGroup1@Domain.com', ChkBoxName2 => 'EmailGroup2@Domain.com', ); foreach my $checkbox_name (keys %checkboxes) { $email_to .= "$checkboxes{$checkbox_name}, " if param($checkbox_name +); # if the checkbox was ticked, the param call returns true, and $em +ail_to gets the email address added. }

    Now I've given you some useful code. That was nice of me, wasn't it? In return, could you do me a favour? Follow the previous poster's advice. Go read Ovid's course on CGI and the other links he sent you. Learn what you are doing. It will save you time and heartache, and it will make your job more interesting and creative.

    andramoiennepemousapolutropon