Posted by bschultz (bschultz), 1 October 2004
I'm having a problem getting this to work. Here's the php code:
Code:<?php if ((!$name) || (!$address) || (!$city) || (!$state) || (!$country) || (!$email) || (!$RadioGroup1) || (!$RadioGroup2) || (!$RadioGroup3) || (!$question)) {
Print "You forgot something. Please use your back buton!";
} else {
$mailto = "me@myaddress.com"; $msgSubject = "my subject here"; $msgBody = " Name: $name\n Address: $address\n City: $city\n State: $state\n Country: $country\n
Computer Type?: $RadioGroup1\n
Connect Speed?: $RadioGroup2\n
Computer Knowledge?: $RadioGroup3\n
Question: $question";
mail($mailto, $msgSubject, $msgBody, "From: $email");
}
?> |
|
Even if every field is filled, I still get the error message to echo. Can someone give me a shove in the right direction? Thanks.
Posted by admin (Graham Ellis), 1 October 2004
a) Do you still get the problem if you reduce the fields in the test to just one or two? First thing I would do is to experiment with reducing the test and seeing if the problem remains or goes away as a further clue.
b) How are the variables set up? If they're coming from a form, have you recently switched to a newer version of PHP with register_globals set off?
c) in ANY case, modify your message / check system so that it tells the user WHICH field(s) are wrong ... it will help them know how to correct the form and it will tell you more about the problem during development
Posted by admin (Graham Ellis), 2 October 2004
Hi, Brian ... I've got back and been having a play ... written a little demo (I needed one anyway) to show how I would tackle an application like yours. Try it out at
http://www.wellho.net/demo/niceform.php4 Code:<?php
$fields = array (youremail => "Your email address", youraddress => "Your Street address", city => "Your city, state/country zipcode/postcode", name => "Your name", what => "Your comment ...");
$aok = 1;
if ($_SERVER[REQUEST_METHOD] == "GET") { $oopsmsg = ""; $form = "Please complete this form<br>"; } else { $oopsmsg = "<BR>INFORMATION NEEDED"; $form = "PLEASE PROVIDE ALL FIELDS ... you missed some!<br>"; }
$form .= "<form method=post><table border=1>"; $email = ""; foreach (array_keys($fields) as $f) { if ($_POST[$f] != "") { $oopsie = ""; $email .= "$f : $_POST[$f]\n"; } else { $oopsie = $oopsmsg; $aok = 0; } $form .= "<tr><td>$fields[$f] $oopsie</td>"; $form .= "<td><input name=$f value='".htmlspecialchars($_POST[$f])."'></td></tr>"; } $form .= "<tr><td> </td><td><input type=submit></td></tr></table></form>";
if ($aok == 1) { mail ("graham@wellho.net","Form Demo",$email); $form = "The information you entered has been emailed. Please follow "; $form .= "<a href=/>this link</a> to return to our home page<br>"; } ?> <html> <head><title>Demonstration - form to email</title></head> <body> <h1>This is a form to email demo in PHP.</h1> <?php print $form;?> <hr>On this demo, all fields must be complete<br> Copyright, Well House Consultants, <?php print (date("Y")); ?> </body> </html> |
|
Posted by admin (Graham Ellis), 3 October 2004
To complete my example, here's the sort of emails I am now receiving, including headers.
Code:From nobody@lightning.he.net Sun Oct 3 06:23:12 2004 Return-Path: <nobody@lightning.he.net> Received: from lightning.he.net ([127.0.0.9]) by wellho.net for <graham@wellho.net>; Sat, 2 Oct 2004 22:05:26 -0700 From: nobody@lightning.he.net Message-Id: <1096779926.4162@lightning.he.net> Date: Sat, 2 Oct 2004 22:05:26 -0700 To: graham@wellho.net Subject: Form Demo X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) on lightning.he.net X-Spam-Level: X-Spam-Status: No, hits=-4.7 required=7.0 tests=BAYES_00,NO_REAL_NAME autolearn=no version=2.64
youremail : dg youraddress : dfgdfg city : dgdfg name : dgdf what : df |
|
Posted by bschultz (bschultz), 3 October 2004
Sorry I haven't posted back sooner...I've been out of town. I eliminated all but one of the fields...and I still get the same error / results. It still echo's the error message.
The variables are coming in on a form. Here's the code:
Code: <form method="post" action="web_feedback3.php"> <p><br> Name: <input name="name" type="text" id="name" /> <br> Address: <input name="address" type="text" id="address" /> <br> City: <input name="city" type="text" id="city" /> <br> State: <input name="state" type="text" id="state" /> <br> Country: <input name="country" type="text" id="country" /> <br> Email Address: <input name="email" type="text" /> <br /> <br> <strong>Computer Type: <label> </label> </strong> <label><br> <input type="radio" name="RadioGroup1" value="Windows"> Windows</label> <br> <label> <input type="radio" name="RadioGroup1" value="Mac"> Mac</label> <br> <label> <input type="radio" name="RadioGroup1" value="Linux"> Linux</label> <br> <br> <strong>Internet Connection Speed: </strong><br> <label> <input type="radio" name="RadioGroup2" value="dial up"> Dial Up</label> <br> <label> <input type="radio" name="RadioGroup2" value="dsl"> DSL</label> <br> <label> <input type="radio" name="RadioGroup2" value="cable"> Cable</label> <br> <br> <strong>Computer Knowledge: </strong><br> <label> <input type="radio" name="RadioGroup3" value="novice"> Novice</label> <br> <label> <input type="radio" name="RadioGroup3" value="proficient"> Proficient</label> <br> <label> <input type="radio" name="RadioGroup3" value="genius"> Genius</label> <br> <br> Please tell us as much information about your problem as you can. We will be in touch with you soon. Thank you.<br> <textarea name="question" cols="40" rows="15" id="question"> </textarea> <br> <br /> <input name="submit" type="submit" value="Submit" /> <input type="reset" name="Reset" value="Reset"> </p> </form> |
|
I'll edit your sample code to suit my needs, and I'll post back tomorrow.
Thanks.
Brian
Posted by bschultz (bschultz), 3 October 2004
Thanks Graham,
I got your code to work, but I had radio buttons in my original form. How can I get those to work in your code. Would I need a second array just for the three radio button categories like I had here:
http://kkbjam.com/pages.php?page=listen.php
Thanks again, Graham.
Brian
Posted by admin (Graham Ellis), 3 October 2004
Nah - I wouldn't bother with another array - simply code something into the existing array that flags a different type of input. I did an example of this with a "select" ... I know very well you do radio programs so wanted radio buttons
but I was having a senior moment ... anyhow, I'm sure you can adapt / adopt.
New demo at:
http://www.wellho.net/demo/veryniceform.php4Code changes: Initial array setup now reads:
Code:$fields = array (youremail => "Your email address", youraddress => "Your Street address", city => "Your city, state/country zipcode/postcode", name => "Your name", agegroup => "Age Group|under 21|21 to 39|40 to 64|65 and over", what => "Your comment ..."); |
|
and interpretaion of it is expanded:
Code:foreach (array_keys($fields) as $f) { if ($_POST[$f] != "") { $oopsie = ""; $email .= "$f : $_POST[$f]\n"; } else { $oopsie = $oopsmsg; $aok = 0; } $options = explode("|",$fields[$f]); if (count($options) < 2) { $form .= "<tr><td>$fields[$f] $oopsie</td>"; $form .= "<td><input name=$f value='".htmlspecialchars($_POST[$f])."'></td></tr>"; } else { $form .= "<tr><td>$options[0] $oopsie</td>"; array_shift($options); $form .= "<td><select name=$f><option value=''> -- Please Choose --"; foreach ($options as $maybe) { $yes = ($maybe == $_POST[$f]) ? " SELECTED":""; $form .= "<option value='$maybe'$yes>$maybe<br>"; } $form .= "</select>"; }
} $form .= "<tr><td> </td><td><input type=submit></td></tr></table></form>"; |
|
(I've given you a bit more there to put it in context)
Posted by bschultz (bschultz), 3 October 2004
perfect! Thanks again for everything Graham.
This page is a thread posted to the opentalk forum
at
www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow
this link.