Need help passing variables to formmail.cgi script
I am building a website for my church and I cant figure out how to pass the variable (subject of the message) to the formmail.cgi (matt wright clone) script. I also want to be able to associate the variable with the email recipient and change the email address that the form sends to the script as users change their subjects. I am also having trouble getting my validation script to force the user to select a subject. If anyone can help with any of these bugs, I would be greatly appreciative. The information about my cgi script is here:
function validate ()
{
if (document.myform.sub.value == "")
{
alert('You must select a subject');
return false;
}
else if (document.myform.realname.value == "")
{
alert('Name cannot be blank');
return false;
}
else if (document.myform.email.value == "")
{
alert('Your email address is required');
return false;
}
else if (document.myform.question.value == "")
{
alert('You left the question box blank. Did you have a question?');
return false;
}
Two things:
<option value==""> Please select one... </option>
You hve used the compaison operator in all your options.
Use:
<option value=""> Please select one... </option>
Change them all.
You must change the subject input, otherwise it will return "".
So, in validate() the last but one line should be:
document.myform.subject.value=document.myform.sub.value;
If it is still not working correctly, show us any errors (also from the server) and the contents of the e-mail if received.
Ok, the validation is working, but it is putting the option value as 1,2,or 3 in the subject of the email being sent. I want it to use my function "findsub" to replace the numeric value with the corresponding subject. I also want to be able to change the recipient of the email as the subject changes. If anyone can help I will be very grateful. Thanks for the help!
function validate ()
{
if (document.myform.sub.value == "")
{
alert('You must select a subject');
return false;
}
else if (document.myform.realname.value == "")
{
alert('Name cannot be blank');
return false;
}
else if (document.myform.email.value == "")
{
alert('Your email address is required');
return false;
}
else if (document.myform.question.value == "")
{
alert('You left the question box blank. Did you have a question?');
return false;
}
Ok, I have put your code in on the server and it wont even send the email now. I then edited my code and have gotten it to display the subject correctly. The only thing left to do is get the "recipient" to change as the user selects from the subject box. The recipient is at the bottom of my code and is being passed to the server script from there. I need to set that = a variable that changes as the subject changes. I can write a function with if statements setting that variable to change to different email addresses as the subject box changes, but how do I call that function from the html?
function validate ()
{
if (document.myform.sub.value == "")
{
alert('You must select a subject');
return false;
}
else if (document.myform.realname.value == "")
{
alert('Name cannot be blank');
return false;
}
else if (document.myform.email.value == "")
{
alert('Your email address is required');
return false;
}
else if (document.myform.question.value == "")
{
alert('You left the question box blank. Did you have a question?');
return false;
}
Your code did not send the email at all. My recipient account did not get the message. It also was putting the email addresses of the recipient into the subject of the email. That is why I changed that. Notice on my latest code. I did not get any errors, but I did not get the desired output. I have got it working now like I want it, but I just need to know how to vary the recipient. You have to notice the "hidden" input at the bottom of my code setting "recipient" to "webmaster@allonschurch.org". This value is submitted as the recipient of the email to the server script when submitted. I just need to be able to check the value of my subject and set this value to the matching recipient.
I changed those 2 lines and it still did not send the email. I got no errors, but I did not get the email in the recipient account I am using to test it. Is there any way to add to my code so it will vary the recipient of the email. My code does send the message correctly, it just sends it to the email provided in the bottom of my code.
I know that, but I need to have it set as a variable so it can change as the subject changes. If I were to add 10 different subjects and sent each one to a different recipient, I need that flexibility. I can do it in a function below my "validate" function, but I am not sure how or where to call it from.
Does this replace my current validation function or does it go underneath it? If it goes underneath it, do I not have to call it somewhere within my html?
I have used this case code and tried to set it up in another function and call it with the "onchange" within my <Select>. It is not sending any email, but the validation still works properly. Take a look at my code.
function validate ()
{
if (document.myform.sub.value == "")
{
alert('You must select a subject');
return false;
}
else if (document.myform.realname.value == "")
{
alert('Name cannot be blank');
return false;
}
else if (document.myform.email.value == "")
{
alert('Your email address is required');
return false;
}
else if (document.myform.question.value == "")
{
alert('You left the question box blank. Did you have a question?');
return false;
}
I got it working. Thanks for all your help. I ended up just using If statements in my "validate" function that set the value of "recipient" for each case. I then set recipient = 'document.myform.recipient.value' at the bottom of my code where it is passed to the server script. It all gets processed at submit so that is the most feasible way to do it anyways.
Bookmarks