croatiankid Posted May 23, 2006 Share Posted May 23, 2006 hi i have a contact form and a proccessing script, which is <?PHPif (!($email) && !($name) && !($lastName) && ! ($des) && ! ($dev) && ! ($seo) && ! ($graph) && ! ($logo) && ! ($banner) && ! ($write) && ! ($maint)) { require("form1.php"); break; } if (!($email) && !($name) && !($lastName)) { require("form2.php"); }?> everything from des to maint are checkboxes. form1.php shows "please input email address", "choose checkbox", lastname, firstname etc. form2.php is the same as form1.php except it doesn't say "please pick a checkbox". firstly: is there an easier way to do this?secondly, but mainly (lol):i put a break here so that after i click submit (with nothing selected/typed in) tha it doesn't create 2 forms. however, instead of creating a second form, it says:Fatal error: Cannot break/continue 1 level in /home/www/ec-labs.awardspace.com/action.php on line 5, which i obviouisly don't want showing lol.so can anyone tell me why it shows up, how to make it not show up, or eventually guide me to a simpler way of proccessing the form and creating the error forms (preferably through php, so that i don't have to "require" a document that is physically on the server) Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 23, 2006 Share Posted May 23, 2006 (edited) The break only works if you are in a loop, a switch() loop for example. use exti() instead, or die() which is the same.The easier way, is bit of hard to explain for me, but I'll try in an edit:[*Edit:]Say you have a form with input elements. The processor validates the input data in php. But there may be data you don't wat to be able to be input, so you may want to switch back from the processor to the form. This is a very common issue. Well, not an issue, but more like a case I suggest, if you are willing to trow back everything you write or spend a lot of time to copy and past things of what you have right now, that you make ONE AND THE SAME file of both the form and the processor. The processor just validates sent data, but if there is none it shows the form. But when there has been data sent, then it validates it against your statements, and stores an error message in a variable if it is unwanted data. After the entire validation, it checks if there has been set an errormessage, and when so it shows the form again but with the error message. I very much hope this is clear Edited May 23, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
justsomeguy Posted May 24, 2006 Share Posted May 24, 2006 The break only works if you are in a loop, a switch() loop for exampleA switch statement isn't a loop, it's just a control structure. You can use the break statement to escape out of a for loop, while loop, or do loop. You can also use a continue statement inside a loop to stop the current iteration and go directly to the next.And to the Croat:You only need 1 form. Consider this:<?php$status_message = "Please fill out the form";$form_submitted = $_POST['submit'];if ($form_submitted){ if ($name == "" || $email == "") $status_message = "Error: all fields are required"; else { //send email, or insert into database, or whatever $status_message = "Thank you"; }}?><html>...<?php echo $status_message; ?><form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"><input type="hidden" name="submit" value="true">...form fields...</form>... Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 24, 2006 Share Posted May 24, 2006 Yeah, indeed for-, while-, do- and foreach loops, but also the SWITCH :)And indeed, only one form is needed, with PHP you can store the message that was created differently by each error We just love PHP don't we? Link to comment Share on other sites More sharing options...
croatiankid Posted May 24, 2006 Author Share Posted May 24, 2006 if ($name == "" || $email == "")this doesn't work for me since i want a user to enter a name, email, surname, and select at least one checkbox. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now