General Community > Scripting Help
php form/MySql db question
onetre:
I could use help with a couple of things:
#1. I've searched everywhere and can't find this at all. I would like to set up a standard php form that has name, subject, and message. The problem I'm having is this...I would like there to be a drop down in the form that allows the user to choose where the form email is sent.
What I'm doing is setting up a socom clan website and in the members section I'm going to place an email form to send out information to certain members. I would like to be able to negotiate this through a drop down...it also might be a good idea to use check boxes for multiple recipients as opposed to the drop down.
#2 Other than the standard pre-setup scripts I've not had any sql experience. For this clan site there are a few very simple scripts that need to be created and I would like to know where to start.
One of these scripts would be a simple db that stores 2 name fields, a date, and a field for about 4 lines of text. It needs to be stored alphabetically by one of the name fields and have a input form on the site then of course be viewed on one of the pages.
I'm not asking anyone to create this script for me (although I wouldn't turn it down), I'm just looking for a very simple tutorial for someting like this. I would like to learn it.
Thanks in advance for any help.
SparkieGeek:
--- Quote from: onetre on October 28, 2003, 11:18:14 AM ---#1. I've searched everywhere and can't find this at all. I would like to set up a standard php form that has name, subject, and message. The problem I'm having is this...I would like there to be a drop down in the form that allows the user to choose where the form email is sent.
--- End quote ---
Should be easy enough...
--- Quote ---What I'm doing is setting up a socom clan website and in the members section I'm going to place an email form to send out information to certain members.
--- End quote ---
How are you authenticating the users? Are all the users allowed to use the form or just you?
--- Quote ---I would like to be able to negotiate this through a drop down...it also might be a good idea to use check boxes for multiple recipients as opposed to the drop down.
--- End quote ---
Where are you storing the list of potential recipients? Will the list of recipients change fairly frequently or is it set?
Jack.R.Abbit™:
--- Quote from: onetre on October 28, 2003, 11:18:14 AM ---I would like to be able to negotiate this through a drop down...it also might be a good idea to use check boxes for multiple recipients as opposed to the drop down.
--- End quote ---
Make the <select> tag allow multiple selections like this:
--- Code: ---<select name="emails[]" size="5" multiple>
<option value="someone@nowhere.com">Clan Member 1</option>
<option value="anyone@nowhere.com">Clan Member 2</option>
<option value="noone@nowhere.com">Clan Member 3</option>
</select>
--- End code ---
That makes a select box that is 5 liines tall and allows multiple selections. When you hit the submit button, the [] makes the selections come through as an array named $emails
Then in the php script, you would just need to get all of the selected email addresses and send the email to all of them. Like this:
--- Code: ---<?php
foreach ($emails as $thisEmail){
# Do something to send the email to $thisEmail
}
?>
--- End code ---
Of course you'll want to add a bit of error checking in there. Like if they even selected any email address.
onetre:
--- Quote ---
--- Quote from: onetre on October 28, 2003, 11:18:14 AM ---#1. I've searched everywhere and can't find this at all. I would like to set up a standard php form that has name, subject, and message. The problem I'm having is this...I would like there to be a drop down in the form that allows the user to choose where the form email is sent.
--- End quote ---
Should be easy enough...
--- End quote ---
--- Quote ---
--- Quote ---What I'm doing is setting up a socom clan website and in the members section I'm going to place an email form to send out information to certain members.
--- End quote ---
How are you authenticating the users? Are all the users allowed to use the form or just you?
--- End quote ---
Yes, all the members will be allowed to use the form. I've already set up a password protected section of the site where this form will reside.
--- Quote ---
--- Quote ---I would like to be able to negotiate this through a drop down...it also might be a good idea to use check boxes for multiple recipients as opposed to the drop down.
--- End quote ---
Where are you storing the list of potential recipients? Will the list of recipients change fairly frequently or is it set?
--- End quote ---
I'm guessing that it won't be a weekly change, but I'm sure people will leave and other members will join. Hopefully people will continue to join and the clan continues to grow. This would of course mean that ease of adding new members would be a plus.
After thinking it through a bit more I've kind of got an idea of what I'm seeing.
Obviously if clan is clicked it sends to everyone. If Alpha team is clicked it sends to those 4 members. And if individuals are clicked it sends to those people.
Thank you for the response by the way.
SparkieGeek:
What Jack.R.Abbit has posted looks good if you want a dropdown list.
If you want a load of tickboxes (as your image suggests) then you should use
--- Code: ---<input type="checkbox" name="alpha[1]" value="alpha1@email.com"/>Person 1
<input type="checkbox" name="alpha[2]" value="alpha2@email.com"/>Person 2
--- End code ---
You could use some JavaScript to automatically check all of Alpha Team members when you click on Alpha Team (look at the SMF Search page for inspiration)
Your PHP script will then look something like this (adapted from Jack.R.Abbit's script):
--- Code: ---<?php
...
foreach ($alpha1 as $thisEmail) {
if ($thisEmail!='') {
# Do something to send an e-mail to $thisEmail
}
}
?>
--- End code ---
Editing the list will be just a case of changing the HTML (which I presume you're comfortable with).
I haven't tested this, but I think it'll work!
Navigation
[0] Message Index
[#] Next page
Go to full version