Forum Moderators: coopster

Message Too Old, No Replies

Registration form

         

music_man

4:02 am on Jan 24, 2006 (gmt 0)

10+ Year Member



hi

This form isn't dying when the user does not type in the right info...


<?

if($_POST["action"] == "Submit") {

$name = stripslashes($_POST['name']);
$address = stripslashes($_POST['address']);
$phone = stripslashes($_POST['phone']);
$mobile = stripslashes($_POST['mobile']);
$email = stripslashes($_POST['email']);
$iwasa = stripslashes($_POST['iwasa']);
$years = stripslashes($_POST['years']);

$result = "0";

if($name == "") {

$message .= "You did not fill in your name<br />";
$result = "1";

}

if($address == "") {

$message .= "Please fill in your address<br />";
$result = "1";

}

if($email == "") {

$message .= "Please fill in your email<br />";
$result = "1";

}

if($iwasa == "") {

$message .= "Please fill in your occupation<br />";
$result = "1";

}

if($years == "") {

$message .= "Please fill in your what year you did it<br />";
$result = "1";

}

if ($result == "1") {

die("$message");

}

else

{

echo "sent"; // mail function goes here

}
}

?>
<div id="page">
<h1>
Registration
</h1>

<br />

<h3>

<fieldset>
<legend>Please fill in all the fields</legend>
<br />
<form action="registration.php" method="post">
<label for="name">Name: </label>
<input type="text" name="name" size="27"></input>
<br />
<br />
<label for="address">Address: </label>
<textarea name="address" rows="10" cols="20"></textarea>
<br />
<br />
<label for="phone">Phone: </label>
<input type="text" name="phone"></input>
<br />
<br />
<label for="mobile">Mobile: </label>
<input type="text" name="mobile"></input>
<br />
<br />
<label for="emailaddress">Email address: </label>
<input type="text" name="email"></input>
<br />
<br />
<span>I was a:</span> <select name="iwasa">
<option>Member
<option>Tutor
<option>Conductor
<option>Accompanist
<option>Administrator
</select>
<br />
<br />
<span>For the years:</span><br /><br />
<input type="text" name="years"></input><br /><br />
<input type="submit" value="Submit"></input>
</form>
</fieldset>
</h3>
</div>

Any ideas?

dreamcatcher

9:34 am on Jan 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the form actually processing? Or is the if statement being ignored completely?

Try changing this line:

<input type="submit" value="Submit">

to this:

<input type="submit" name="Submit" value="Submit">

and then this:

if($_POST["action"] == "Submit")

to this:

if (isset($_POST['Submit']))

dc

Godluck

10:23 am on Jan 24, 2006 (gmt 0)

10+ Year Member



Hi

If the use of $_POST[] array is not working, try using the $_REQUEST[], preferably $_REQUEST['Submit'] not $_REQUEST['action'], it works for me.

dreamcatcher

4:39 pm on Jan 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



and also use:

print_r($_POST)

to see whats set.

dc

music_man

9:52 pm on Jan 24, 2006 (gmt 0)

10+ Year Member



Thanks.

Works a treat. Any ideas on how to separate the spaces in the address field by >br /<?

Thanks

music_man

4:10 am on Jan 26, 2006 (gmt 0)

10+ Year Member



<br /> I mean.

dreamcatcher

6:52 am on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If displaying as HTML, us the nl2br() function

$address = nl2br($_POST['address']);

If in a text file use \n

dc