...

View Full Version : List/Radio Form Help



As5a5sIn5
05-20-2004, 06:30 AM
Okay...I've been working on some automatic mail PHP forms...now I'm stuck...
How do I make it so a listbox answer is e-mailed...here's what I mean

Here's HTML

<form action="quiz.php" method="post">
<font face="Tunga"><b>Fill out the following questions honestly and arccuratly for <i>best</i> results</b>
<br><br>
Name: &nbsp;&nbsp;<input type="text" name="name" size="25" maxlength="256">
<br>
Email: <input type="text" name="email" size="25" maxlength="256">
<br><br>
and our good friend Mr. PHP

<html>
<?php
mail(
"A n t h o n y H u r s t@balhsnfjnsd.com"
"Love Quiz!"
"{$_POST['name']} ({$_POST['email']})has filled out a love quiz! Here are their answers!";
?>
</html>

now wut would be the $_POST['????'] for a listbox or radio button or text box????

raf
05-20-2004, 08:27 AM
i don't understand the question.

can you explain some more?

As5a5sIn5
05-20-2004, 08:36 AM
Okay here's an example coding that is actually in affect...


<form action="updates.php" method="post">
Name: &nbsp;&nbsp;<input type="text" name="name" size="20" maxlength="100"><br>
E-mail: &nbsp;<input type="text" name="email" size="20" maxlength="100"><br>
<input type="submit" value="Get Updates!">

See how in that form name="email" and name="email...
it makes it a variable for the php...

mail(
$_POST['email'],
"Welcome {$_POST['name']}",
"Just e-mailing you to inform you that you will recieve site updates
\n Thanks for Joining,
\n JAcostuff.com
");

...see how the $_POST['email'] $_POST['name']
make it connected from the previous page's name="email" name="name"

Now how do I "Connect it" with other form types such as radio buttons, list boxes, text area's etc.

raf
05-20-2004, 08:44 AM
You need to loop thropugh the formcollection. Like

foreach ($_POST as $var=>$value){
}

If you just wan't to print the answers, then you need to be able to filter them out. So all formfields that contain an answer should have the same first x letters in there name. Like answ1, answ2, answ3 etc.
None of the non-answer formfields should have this first 'answ' at the start of there name.

Then you can go



$answers='';
foreach ($_POST as $var=>$value){
if (substr($var, 0, 4)=='answ'){
$answers .= ('Answer to question ' . substr($var,4) . ': ' . $value . '<br />') ;
}
}


$answer will then contain all answers

As5a5sIn5
05-21-2004, 12:32 AM
Thanks...I'm gonna have to read up on php a lil more 2 understand that^ :o

firepages
05-21-2004, 12:55 PM
with say
<input type="radio" name="radiobutt" value="yes" />
<input type="radio" name="radiobutt" value="no" />

then {$_POST['radiobutt']} is good enough (will equal whatever is selected)

for multiples , say checkboxes ..make the name an array by adding '[]' to the name

1<input type="checkbox" name="checkbutt[0]" value="yes" />
2<input type="checkbox" name="checkbutt[1]" value="no" />
3<input type="checkbox" name="checkbutt[2]" value="maybee" />
4<input type="checkbox" name="checkbutt[3]" value="perhaps" />

then if checked,
<?$_POST['checkbutt'][0]?>will = 'yes'


errr & could you tone down the `thanks CF` bit of your sig (nice thought but a bit heavy ;))

As5a5sIn5
06-09-2004, 02:45 AM
with say
<input type="radio" name="radiobutt" value="yes" />
<input type="radio" name="radiobutt" value="no" />

then {$_POST['radiobutt']} is good enough (will equal whatever is selected)

for multiples , say checkboxes ..make the name an array by adding '[]' to the name

1<input type="checkbox" name="checkbutt[0]" value="yes" />
2<input type="checkbox" name="checkbutt[1]" value="no" />
3<input type="checkbox" name="checkbutt[2]" value="maybee" />
4<input type="checkbox" name="checkbutt[3]" value="perhaps" />

then if checked,
<?$_POST['checkbutt'][0]?>will = 'yes'



So basically this would work?

If($_POST['checkbutt'][0]){
Script Here
}elseif($_POST['checkbutt'][1]{
Script Here
}

bcarl314
06-09-2004, 02:54 AM
Seriously, would you name a form element checkbutt ??? :D

As5a5sIn5
06-09-2004, 03:28 AM
:D Haha...jus relized that...but seriously...would it work?
or would you have to put
if($_POST['checkbutt'][0] == true){
SCRIPT HERE
}

firepages
06-09-2004, 03:43 AM
no cos checkbutt won't == true , it will equal whatever value you gave it in the form..



<?
if(!empty($_POST['checkbutt'][0])){
//should work
}
?>

As5a5sIn5
06-09-2004, 04:05 AM
thanks much! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum