...

View Full Version : php and user form



rndilger
11-05-2007, 02:04 AM
Hello, I'm having trouble with the following code. I know there's something small that's wrong with the code, but I can't find the error. When I submit the form, it doesn't seem to pass the variables to the proper function. The live version of this code can be accessed at: http://www.rndpig.com/register.php. Note that all the variables that aren't currently being used, WILL be used eventually.

Thanks,

Ryan



<?php

function Register(){
global $name, $email, $address, $city, $state, $zip, $phone, $name_mt, $email_mt, $address_mt, $city_mt, $state_mt, $zip_mt, $phone_mt, $invalid;
global $a2dfam, $a2dind, $a2dstu, $a1dfam, $a1dind, $a1dstu, $na2dfam, $na2dind, $na2dstu, $na1dfam, $na1dind, $na1dstu;
global $dec2dfam, $dec2dind, $dec2dstu, $dec1dfam, $dec1dind, $dec1dstu, $banquet, $pizza, $brunch, $dues;

RegisterForm();

}

function RegisterForm(){
global $name, $email, $address, $city, $state, $zip, $phone, $name_mt, $email_mt, $address_mt, $city_mt, $state_mt, $zip_mt, $phone_mt, $invalid;
global $a2dfam, $a2dind, $a2dstu, $a1dfam, $a1dind, $a1dstu, $na2dfam, $na2dind, $na2dstu, $na1dfam, $na1dind, $na1dstu;
global $dec2dfam, $dec2dind, $dec2dstu, $dec1dfam, $dec1dind, $dec1dstu, $banquet, $pizza, $brunch, $dues;

echo "<form method='POST' name='register' action='../register.php' enctype='multipart/form-data'>
<table align='center' border='0'>
<tr><td colspan='3' align='center'><h1>Registration</h1><br><br></td></tr>
<tr>
<td align='right'>Name(s) of Adults Attending </td>
<td align='left'><input type='text' size='50' maxlength='50' name='name' value='$name'></td>
<td align='left' width='100'>$name_mt</td>
</tr>
<tr>
<td align='right'>E-mail </td>
<td align='left'><input type='text' size='50' maxlength='50' name='email' value='$email'></td>
<td align='left' width='100'>$email_mt$invalid</td>
</tr>
<tr><td colspan='3'>&nbsp;</td></tr>
<tr>
<td align='right'>Address </td>
<td><textarea rows='3' name='address' cols='30'>$address</textarea></td>
<td align='left' width='100'>$address_mt</td>
</tr>
<tr>
<td align='right'>City </td>
<td align='left'><input type='text' name='city' size='20' value='$city'></td>
<td align='left' width='100'>$city_mt</td>
</tr>
<tr>
<td align='right'>State </td>
<td align='left'><input type='text' name='state' size='15' value='$state'></td>
<td align='left' width='100'>$state_mt</td>
</tr>
<tr>
<td align='right'>Zip </td>
<td align='left'><input type='text' name='zip' size='10' value='$zip'></td>
<td align='left' width='100'>$zip_mt</td>
</tr>
<tr>
<td align='right'>Phone </td>
<td align='left'><input type='text' name='phone' size='15' value='$phone'></td>
<td align='left' width='100'>$phone_mt</td>
</tr>
<tr><td colspan='3'>&nbsp;</td></tr>
<tr><td></td>
<td align='left' colspan='2'>
<input type='hidden' name='action' value='CheckInfo'>
<input type='submit' value='Verify Registration'>
</td></tr>
</table></form>";
}

function CheckInfo(){
global $name, $email, $address, $city, $state, $zip, $phone, $name_mt, $email_mt, $address_mt, $city_mt, $state_mt, $zip_mt, $phone_mt, $invalid;
global $a2dfam, $a2dind, $a2dstu, $a1dfam, $a1dind, $a1dstu, $na2dfam, $na2dind, $na2dstu, $na1dfam, $na1dind, $na1dstu;
global $dec2dfam, $dec2dind, $dec2dstu, $dec1dfam, $dec1dind, $dec1dstu, $banquet, $pizza, $brunch, $dues;

if(empty($name) || empty($email) || empty($address) || empty($city) || empty($state) || empty($zip) || empty($phone)){
if ($name == ""){ $name_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($email == ""){ $email_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($address == ""){ $address_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($city == ""){ $city_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($state == ""){ $state_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($zip == ""){ $zip_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($phone == ""){ $phone_mt = "<span style='color:#000000;'>< required field</span>"; }
Register();
}

if(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$",stripslashes(trim($email)))){
$invalid = "<span style='color:#000000;'>< invalid entry</span>";
Register();
}else{
Verify();
}

}

function Verify(){
global $name, $email, $address, $city, $state, $zip, $phone, $name_mt, $email_mt, $address_mt, $city_mt, $state_mt, $zip_mt, $phone_mt, $invalid;
global $a2dfam, $a2dind, $a2dstu, $a1dfam, $a1dind, $a1dstu, $na2dfam, $na2dind, $na2dstu, $na1dfam, $na1dind, $na1dstu;
global $dec2dfam, $dec2dind, $dec2dstu, $dec1dfam, $dec1dind, $dec1dstu, $banquet, $pizza, $brunch, $dues;

echo "<br><br><form method='post' name='verify' action='../register.php' enctype='multipart/form-data'>
<table align='center' border='0' cellpadding='5' cellspacing='0' class='Large bold'>
<tr><td colspan='2' align='center'><h1>Verify Registration</h1><br><br><br></td></tr>
<tr><td align='right' class='greybg'>Name(s):</td><td align='left'>$name</td></tr>
<tr><td align='right' class='greybg'>E-mail:</td><td align='left'>$email</td></tr>
<tr><td class='greybg'>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td align='right' class='greybg'>Address:</td><td>$address</td></tr>
<tr><td align='right' class='greybg'>City:</td><td align='left'>$city</td></tr>
<tr><td align='right' class='greybg'>State:</td><td align='left'>$state</td></tr>
<tr><td align='right' class='greybg'>Zip:</td><td align='left'>$zip</td></tr>
<tr><td align='right' class='greybg'>Phone:</td><td align='left'>$phone</td></tr>
<tr><td colspan='2'>&nbsp;</td></tr>
<tr><td align='center' colspan='2'>
<input type='hidden' name='action' value='Submit'>
<input type='hidden' name='name' value='$name'>
<input type='hidden' name='email' value='$email'>
<input type='hidden' name='address' value='$address'>
<input type='hidden' name='city' value='$city'>
<input type='hidden' name='state' value='$state'>
<input type='hidden' name='zip' value='$zip'>
<input type='hidden' name='phone' value='$phone'>
<input type='submit' value='Submit'>
<input type='button' value='Modify Registration' onclick='history.go(-1)'>
</td></tr>
</table></form>";


}

function Submit(){
global $name, $email, $address, $city, $state, $zip, $phone;
global $a2dfam, $a2dind, $a2dstu, $a1dfam, $a1dind, $a1dstu, $na2dfam, $na2dind, $na2dstu, $na1dfam, $na1dind, $na1dstu;
global $dec2dfam, $dec2dind, $dec2dstu, $dec1dfam, $dec1dind, $dec1dstu, $banquet, $pizza, $brunch, $dues;

$to = "Ryan <test@test.com>";
$from = $name . "<". $email .">";

$headers = "MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset='iso-8859-1'\n" .
"From: $from\r\n" .
"Date: ".date("r")."\r\n";

$subject = "Registration";

$message = "Below is information from a recently submitted Registration.\n\n" .
"Name(s): ".$name."\nE-mail: ".$email."\n\n" .
"Address: \n".$address."\n".$city.", ".$state." ".$zip."\n\nPhone: ".$phone."";

mail($to, $subject, $message, $headers);

echo "<br><br><table align='center' class='black bold'><tr><td align='center'>
<h2>Thank you, your registration was successfully submitted.</h2><br><br></td></tr></table>";

}

switch ($action){

case "Register":
Register();
break;

case "RegisterForm":
RegisterForm();
break;

case "CheckInfo":
CheckInfo();
break;

case "Verify":
Verify();
break;

case "Submit":
Submit();
break;

Default:
Register();
break;
}
?>

Fumigator
11-05-2007, 02:17 AM
Does your PHP install have register_globals turned on?

rndilger
11-05-2007, 02:20 AM
Well, that was easy enough to diagnose. Register_globals always USED to be turned on, but now it is turned off. Is there an easy way that I can modify this code to get around this issue?

rndilger
11-05-2007, 12:17 PM
I apologize for bumping this post. I am still learning php and need a little assistance with this problem.

Could anyone please tell me how I can modify the above code to get around using global variables? Do I need to pass variables directly in the function parameters?

Thanks,

Ryan

aedrin
11-05-2007, 05:23 PM
I think your primary goal right now should be to learn some proper PHP techniques.

Your use of functions to echo content and liberal use of global indicates that you are not using the language correctly.

You should not use functions to seperate code, you should use functions to abstract logic for re-use.

idalatob
11-06-2007, 06:52 AM
I hate to say it, but theres something about your code that makes it horribly inefficient. Sorry about that, but its just true. Your use of functions is inappropriate. Not a huge balls up though!

Everybody makes mistakes and ive made tons of them. But ive also made tons of forms, so if you would like a couple of samples, just pm and ill mail them to you or something.

I don't really want to post them here, as its a little overkill.

aedrin
11-06-2007, 03:47 PM
Could anyone please tell me how I can modify the above code to get around using global variables? Do I need to pass variables directly in the function parameters?

The problem is your use of register_globals. As this is a means of coding too lazy (one should always be as lazy as possible, but not too lazy).

There already is a global variable made available to you with all the GET and POST variables, ($_GET, $_POST or $_REQUEST). So you can use those directly.





if ($zip == ""){ $zip_mt = "<span style='color:#000000;'>< required field</span>"; }
if ($phone == ""){ $phone_mt = "<span style='color:#000000;'>< required field</span>"; }




Lines like that are perfect candidates for arrays.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum