uramagget Posted July 14, 2007 Share Posted July 14, 2007 <? include "top.txt"; // get posted data into local variables $username = Trim(stripslashes($_POST['username'])); $email = Trim(stripslashes($_POST['email'])); $password = Trim(stripslashes($_POST['password'])); $subdomain = Trim(stripslashes($_POST['subdomain'])); $currenturl = Trim(stripslashes($_POST['currenturl'])); //Send to, and subject. $emailto = "[email protected]"; $subject = "PokeRindin Hosting"; // Check if filled in/empty if (Trim($email)==""){ echo "You forgot to fill in your E-Mail"; } elseif (Trim($username)==""){ echo "You forgot to fill in your Username"; } elseif (Trim($password)==""){ echo "You forgot to fill in your Password"; } elseif (Trim($subdomain)==""){ echo "You forgot to fill in your Subdomain"; } // prepare email body text $Body = ""; $Body .= "Username: "; $Body .= $username; $Body .= "\n"; $Body .= "Password: "; $Body .= $password; $Body .= "\n"; $Body .= "Sub-domain: "; $Body .= $subdomain; $Body .= "\n"; $Body .= "Current URL: "; $Body .= $currenturl; $Body .= "\n"; // send email $success = mail($emailto, $subject, $Body, "From: <$email>"); // redirect to success page if ($success){ echo "Your application was sent to Rindiny, and is awaiting approval. Can you join our forum while you wait, please?"; } else{ echo "Eeek! the form couldn't go through right. Only one thing to do. Contact Rindiny([email protected]), or try the form again. D: "; } include "bottom.txt"; ?> I'm trying to write a form where it makes users require them to fill it in, though even with the if code, the form is submitted, so I can't find out why this doesn't work. Link to comment https://forums.phpfreaks.com/topic/59951-php-form-validatign/ Share on other sites More sharing options...
lur Posted July 14, 2007 Share Posted July 14, 2007 When finding a required field is empty, the only action you take is printing an error message. If you want to stop the remaining code from executing you must cause it to do so by using, for example, exit(); Link to comment https://forums.phpfreaks.com/topic/59951-php-form-validatign/#findComment-298284 Share on other sites More sharing options...
uramagget Posted July 14, 2007 Author Share Posted July 14, 2007 So I add exit(); inside of every part that checks for empty fields like this? if (Trim($email)==""){ echo "You forgot to fill in your E-Mail"; exit(); } like this? Also, why don't I use die, instead of exit? Link to comment https://forums.phpfreaks.com/topic/59951-php-form-validatign/#findComment-298304 Share on other sites More sharing options...
sinisake Posted July 14, 2007 Share Posted July 14, 2007 you can use die() too... Link to comment https://forums.phpfreaks.com/topic/59951-php-form-validatign/#findComment-298323 Share on other sites More sharing options...
uramagget Posted July 14, 2007 Author Share Posted July 14, 2007 Let me try that. Link to comment https://forums.phpfreaks.com/topic/59951-php-form-validatign/#findComment-298331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.