Gossamer Forum
Home : Products : DBMan : Customization :

new sub

Quote Reply
new sub
I have an evaluation "form-to-mail" form on my current site, which I would rather have in my database. I don't want it to be "part" of the database entries, rather that the user just is able to:

1. fill out the form

2. hit "submit"

3. A thank you kind of page appears

4. An email is sent to the admin with the info that was on that form.

I spent most of last night & today trying to do this myself. Of course it doesn't work, but I would appreciate knowing if I am at least on the right track.

Also, I did think perhaps that because I have select fields on this form that this might cause a problem? Anyway, here is what I have done so far:

in the db.cgi sub_main added:

elsif ($in{'recruit_eval'}) { if ($per_view) { &html_recruit_eval; } else { &html_unauth; } }

in the html.pl at the sub html_footer added:

print qq!| <A HREF="$db_script_link_url&recruit_eval=1"><b>Recruit Eval</b></A> |! if ($per_view);

then in the html.pl added new subs:

sub html_recruit_eval {
# --------------------------------------------------------
# Recruit Evaluation Form

$page_title = "Recruit Evaluation";
&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>Please complete the form below once your have traveled with a recruit.</FONT>
|;
# < -- End page text -->

print qq|
<P>
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="$db_key" value="$db_key">
|;
print qq|
<table height="527" width="450" align="center">
<FONT face=Arial size=2>
<td style="border: 1 solid #3C2C20" width="450" bgcolor="#d5c6bb" height="66"><font color="#000000">1. <FONT face=Arial size=2> What is <b>your</b>
Primary NOR Guild Name</FONT>?&nbsp; </font></FONT><font color="#000000"><input type=text name="norname" size="30" style="background-color: rgb(234,226,225); color: rgb(0,0,0);">&nbsp;&nbsp;&nbsp;&nbsp;
</font>&nbsp;&nbsp;&nbsp;
<tr>
<td height="66" width="450" style="border: 1 solid #3C2C20" bgcolor="#d5c6bb"><font color="#000000"><FONT face=Arial size=2>2. What is the <b>name
of the recruit</b> you traveled with? </FONT><input name="RecruitsName" size="28" style="background-color: rgb(234,226,225); color: rgb(0,0,0);"></font></td>
</tr>
<tr>
<td height="55" width="450" style="border: 1 solid #3C2C20" ; bgcolor="#d5c6bb"><font color="#000000"><font face="Arial" size="2">3. How many
<b> times</b>
have you traveled with this recruit? </font><select name="Traveled" size="1" style="background-color: rgb(234,226,225); color: rgb(0,0,0);">
<option>Choose One</option>
<option value="0">None</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">More then 4</option>
</select> </font> </td>
</tr>
<tr>
<td height="251" width="450" style="border: 1 solid #3C2C20" bgcolor="#d5c6bb">
<p align="left"><font face="Arial" size="2" color="#000000">11. If you have anything <b>else
to add</b> that might <b> help</b> the chances of this recruit to be accepted
into *NOR/!, or any other pertinent information that might help us form
our decision for or against, please state your opinions below:</font><font color="#000000">&nbsp;
<textarea wrap="hard" name="AddInfo" cols="53" rows="7" style="background-color: rgb(234,226,225); color: rgb(0,0,0);"></textarea> </font> </p>
</td>
</tr>
<tr>
<td height="69" width="450" style="border: 1 solid #3C2C20" bgcolor="#d5c6bb">
<p align="center"><font face="Arial" size="2" color="#322821">The information entered
here will be kept in the strictest confidence of the Rathe Duchy
officers.</font></p>
<p align="center"><font face="Arial" size="2" color="#322821"><b>Clicking Submit</b> will forward your responses.</font></p>
</td>
</tr>
</table>
</center>
|;
print qq|
<p>
<center><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Reset"></center></form> |;

&html_footer;
&html_page_bottom;
}

sub html_recruit_eval_success {
#------------------------
%rec = &get_record($in{$db_key});

open (MAIL, "$mailprog") or &cgierr("Can't start mail program");
print MAIL "To: dianarae\@bellsouth.net\n";
print MAIL "From: Members Recruit Evaluation\n";
print MAIL "Subject: insert the subject line here\n\n";

print MAIL "-" x 75 . "\n\n";

print MAIL "Recruit Evaluation.\n\n";

print MAIL "Primary NOR Guild Name: $norname.\n\n";
print MAIL "Recruits name is: $RecruitsName\n";
print MAIL "Traveled with Recruit: $Traveled\n\n";
print MAIL "Additional Info: $AddInfo\n\n";

close (MAIL);

}

&html_print_headers;
print qq|
## add body tags
<center><table border=1 cellpadding=5 cellspacing=3 width=500 align="center">
<tr><td colspan=2><FONT size=1><b>$html_title: Submission Complete</b></FONT> </td></tr>
<tr><td><p><center><$font_title><b>Submission Complete </b></font></center><br>
<tr>
<td width="346" style="border: 2 groove #2B0000; padding: 0" height="142" bgcolor="#d5c6bb">
<p><font size="2" face="Arial" color="#110000">Thank you for
information about this recruit.&nbsp; Your input is a very
important tool in determining their acceptance in to The New
OutRiders. &nbsp;</font></p>
<p><font size="2" face="Arial" color="#110000">If any of this
information is incorrect, or you wish to make changes, please go
back to the quiz form and change it. Most browsers will let you
use the <b>BACK</b> button right now and it should remember the
answers you typed in already. Just correct what you need to, then
submit again.</font></p>
</tr>
|;
&html_footer;
print qq| </td></tr></table></center>## add ending body tags
|;
}

I need to know if I am even on the right track here. Any input would be appreciated. Thank you.
Diana Rae
Quote Reply
Re: [dianarae] new sub In reply to
You're on the right track, but hitting the submit button in html_recruit_eval won't get you anywhere. The submit button needs a name: <input type="submit" name="submit_eval" value="submit">

Then add this line to sub main in db.cgi:

elsif ($in{'submit_eval'}) { if ($per_view) {&html_recruit_eval_success(%in); }}

The code could further be improved by seperating the actual mailing routine from the html output:

elsif ($in{'submit_eval'}) { if ($per_view) {&recruit_eval; }}

Add this in db.cgi:

sub recruit_eval {

# %in will be available here. No need to retrieve it.

# do stuff to send mail, store errors in $status, if there are none,

#set $status to "ok"

# if mail was successful:

if ($status eq "ok") {

&html_recruit_eval_success(%in);}

else {

&html_recruit_failure ($status);}

}

Just an example. The code would also work without this, but it would be more elegant and you could trap errors.

Also, you need to declare the variables in sub html_recruit_eval_success as you have it. The submitted values are stored in %in. You can use $in{'RecruitsName'} or you have to declare "my $RecruitsName = $in{'RecruitsName#};".
kellner
Quote Reply
Re: [kellner] new sub In reply to
Thanks Kellner, I will give it a go.

I have a question though. What about the drop down menu & text area I am usuing in the form. They are not specified in the .cfg file. Do they need to be?

If not, is the way I have them layed out correct?

Thanks. Smile
Diana Rae
Quote Reply
Re: [dianarae] new sub In reply to
You need to specify dropdown lists and such in the cfg-file only when you want to use field values from the database itself. Otherwise, you can manually write as many miles of dropdown lists as you like, so the answer is: no, they don't need to be specified in the cfg-file in your case.

.
kellner
Quote Reply
Re: [kellner] new sub In reply to
OK. I am working on the code you gave me. So, Now I have - in the .cgi main:

#### Following 3 lines adds the recruit evaluation
elsif ($in{'recruit_eval'}) { if ($per_view) { &html_recruit_eval; } else { &html_unauth; } }
elsif ($in{'submit_eval'}) { if ($per_view) {&recruit_eval; }}
elsif ($in{'submit_eval'}) { if ($per_view) {&html_recruit_eval_success(%in); }}

Are all 3 of these lines needed?

And I did as you suggested & added the sub in the .cgi.

Finally, as to my question of the drop-down menu. I have it entered as it is in my html file. Does that work in DB Man for drop downs? Or, do I need to change that code?

Thanks! Laugh
Diana Rae
Quote Reply
Re: [dianarae] new sub In reply to
As I said before: Yes, the dropdown will work.

No, you don't need all three lines. The last two are alternatives. Look at them: Both test whether there is $in{'submit_eval'}. This can't work like this.

Keep the last of the two lines (the one which calls html_recruit_eval_success) if you stick to your original approach. Keep the first if you went for my additional suggestion and actually wrote a sub recruit_eval in db.cgi.
kellner