NickG21 Posted January 10, 2007 Share Posted January 10, 2007 hey, i am making a validation page for numerous forms all stored in the same session();i was wondering if i use<?phpsession_start(); foreach($_POST as $key => $var) { $_SESSION[$key] = $var; } ?>to assign all of my variables (which have different names for every form) is it necessary for me to sayif(isset($_POST['buttonname']))blah blah blahor can i just go right into my validationif(empty($_POST[$key])){blah blah Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/ Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 Nick, please use [nobbc][code]...[/code][/nobbc] tags around your code.As for what you do, it's up to you, it's always best to validate some how before doing anything with a value.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157398 Share on other sites More sharing options...
NickG21 Posted January 10, 2007 Author Share Posted January 10, 2007 sorry about the non-code tags, would it be possible for me to send each form action to validation.php and at the beginning use:[code]<?phpsession_start();foreach($_POST as $key => $var) { $_SESSION[$key] = $var; } [/code]in order to set the variables, check if the particular button for a particular form was set[code]if(isset($_POST['SendMessage'])){[/code]<--Validation code-->then if the variables are processed correctly use a [code]session_write_close();[/code] after the validation for each is complete and the user is sent to the next form? Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157405 Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 You can do isset, empty, just !, etc.If you're expecting a number, use intval(). If you're expecting a string, clean it first, then you could use strlen, !, or others.It's personal preference. Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157410 Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 it is not necessary... after a submit, $_POST is an array of all the values that were submited, nothing more... but if you want only values that are filled in...[code]<?phpsession_start(); foreach($_POST as $key => $var) if(!empty($_POST[$key])) $_SESSION[$key] = $var;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157417 Share on other sites More sharing options...
NickG21 Posted January 10, 2007 Author Share Posted January 10, 2007 im not looking for just variables that filled in, that was just a basic example, what i want to do is write different validations for different input variables, and if they all pass i want to load the "next" form in the window in which that one was just passed from:[code]if(count($error) > 0){ header("Refresh: 3; URL= http://www..../ListInfo.php"); echo "<input type='hidden' value='' name='step'>"; <--- makes the initial page headerImage keep the ListInfo Form open instead of going on echo "Please Correct Your Errors Before Proceeding"; $error[] = "Please Fix Errors and Re-Submit";}ELSE{ include_once('headerImage.php'); <-- includes main page and increments the step by 1 to load the next form}[/code]i am just unable to pass more than one forms information variables into validation.php, i don't know how to go on with it. that is why i wanted to just put certain validations for individual variables so that if they aren't set it won't go through that code but if they are it will only use that code. this sounds confusing to me writing it so if you don't understand i don't blame you ill try to clean it up a little bit Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157435 Share on other sites More sharing options...
ToonMariner Posted January 10, 2007 Share Posted January 10, 2007 becareful validating form elements.Using isset is a bit of a red herring - posting empty fields still SETS that var name in the postheaders.empty will return true (ie will detect an empty var) if your var is set to 0 - you may want 0....I tend to use type casting when validating forms - I find it helps. Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157442 Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 In addition to what ToonMariner just said, there are many acceptable methods of validating form elements, but I challenge you to come up with the [i]best[/i] for you. What I mean by that is this: don't settle for it just working. Try it out on a server with error reporting set to the highest level and make sure you don't have any errors or warnings appear. In function, you can check if(isset($_POST['submit'])) or if($_POST['submit']), but only the former one will be entirely sound. If you turn error reporting on full, you'll get the warning that you are referencing an undefined key 'submit' with the second. Will it work? Probably, but it's not the best practice. A proper understanding of all the available functions will lead you to your own solution on what works for you.Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/33596-is-isset-necessary/#findComment-157472 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.