/    Sign up×
Community /Pin to ProfileBookmark

Contact Form Help

Should this be in HTML or PHP, Not sure.

But I got my contact page body –

[code]<body>
<br>
<div align=”center”>You can contact teh staffz using this contact form, just fill it out and press submit!</div><br>
<table width=”250″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr>
<th scope=”col”> <form method=”POST” action=”mailer.php”>
<div align=”left”>Name:<br>
<input type=”text” name=”name” size=”19″>
<br>
<br>
Your email:<br>
<input type=”text” name=”email” size=”19″>
<br>
<br>
Message:<br>
<textarea rows=”9″ name=”message” cols=”40″></textarea>
<br>
<br>
<input type=”submit” value=”Submit” name=”submit”>
</div>
</form></th>
</tr>
</table>
</body>[/code]

and mailer.php

[code=php]<?php
if(isset($_POST[‘submit’])) {
$to = “[email protected]”;
$subject = “Contact”;
$name_field = $_POST[‘name’];
$email_field = $_POST[’email’];
$message = $_POST[‘message’];

$body = “From: $name_fieldn E-Mail: $email_fieldn Message:n $message”;

echo “Data has been submitted to $to!”;
mail($to, $subject, $body);
} else {
echo “There was an error”;
}
?> [/code]

How do I make some kind of check box or somthing that lets me choose who it send it too, like – Contact : StaffMember1 or StaffMember2.

I know I got to add an if function, but I’m a newb. :]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 15.2005 — [i][Edited to use radio button instead of checkbox][/i]
<i>
</i>&lt;p&gt;Send To:&lt;br&gt;
&lt;input name=sendto type=radio value=1 checked&gt;Staff Member 1&lt;br&gt;
&lt;input name=sendto type=radio value=2&gt;Staff Member 2&lt;/p&gt;

[code=php]
switch($_POST['sendto'])
{
case 1:
$to = "[email protected]";
break;
case 2:
$to = "[email protected]";
break;
default:
# shouldn't get here, but just in case:
$to = "[email protected]";
}
[/code]
Copy linkTweet thisAlerts:
@JaelanFeb 15.2005 — But if they want the ability to send it to multiple emails, I don't think that would work. (correct me if I am wrong, cause I'm not completely all-knowing in the way the $_POST variable works w/ checkboxes)

Thus, I would do something like this:

<i>
</i>&lt;p&gt;Send To:&lt;br&gt;
&lt;input name="sendto_1" type=checkbox value=1 checked&gt;Staff Member 1&lt;br&gt;
&lt;input name="sendto_2" type=checkbox value=2&gt;Staff Member 2&lt;/p&gt;


[code=php]
$to = "";
for ($i=1;$i<=$numEmails;$i++) {
$sendto = "sendto_{$i}";
if ($_POST[$sendto]) {
if ($to) { //variable already exists, therefore add the next email comma delimited
$to .= ", {$_POST[$sendto]}";
}
else {
$to = $_POST[$sendto];
}
}
}
[/code]


Jaelan
Copy linkTweet thisAlerts:
@pixel-artist-2authorFeb 15.2005 — Is there a way to make it so you can only select 1 check box? ?

EDIT: or I can go with the other way, but where do I put in the e-mails?
Copy linkTweet thisAlerts:
@NogDogFeb 16.2005 — [i]Originally posted by pixel-artist-2 [/i]

[B]Is there a way to make it so you can only select 1 check box? ?



EDIT: or I can go with the other way, but where do I put in the e-mails? [/B]
[/QUOTE]

Oops, that's what I was thinking of, but typed it up wrong. replace "checkbox" with "radio" in the sample HTML I gave above (which I'll go fix now).
Copy linkTweet thisAlerts:
@pixel-artist-2authorFeb 16.2005 — w00t thanks. I spent 3 hours on stupid research paper.
Copy linkTweet thisAlerts:
@JaelanFeb 16.2005 — heh, well now you can do both if you chose ? oh well
×

Success!

Help @pixel-artist-2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...