NickG21 Posted January 8, 2007 Share Posted January 8, 2007 good morning and happy monday to everyone,the only question that i have is if i can include a validation.php page with the code to validate 6 different forms. every form has a different name for the "submit/next" button and all of the fields that are passed have different labels. would i be able to just do all of the validation in that one page with just if(isset('submit')){blah blah...}if(isset('next')){blah blah...}etc......i think this should work fine but id like to be a little mroe sure before i decide to put in validation for 60 different form fields.thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/ Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 Did you try it?HINT: You'll need to use $_POST['submit'] Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155826 Share on other sites More sharing options...
NickG21 Posted January 8, 2007 Author Share Posted January 8, 2007 i believe that it will work, however after the validation completes i want to send it back to the previous form page if it did not complete the validation and if it does i want to process onto the next form to be included.all of the forms are supposed to be redisplayed like this on one main form[code] <?php IF (!isset($_POST['step'])) { include "ListInfo.php"; ELSEIF ($_POST['step'] == 2){ include "OptServices.php";} ELSEIF ($_POST['step'] == 3){ include "ContInfo.php";} ELSEIF ($_POST['step'] == 4){ include "BillInfo.php";} ELSEIF ($_POST['step'] == 5){ include "Survey.php";} ELSEIF ($_POST['step'] == 6){ include "Terms.php";} ?>[/code]any idea how i could say send back to ListInfo.php if it didn't correctly process?error code:[code]if(count($error) > 0){ echo "Please Correct Your Errors Before Proceeding";}ELSE{ include_once("HeaderImage.php");}}[/code]if all of the fields are correct everything continues perfectly, i just don't know how to redisplay the original form, echoing to correct invalid entries Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155937 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 header('Location: ListInfo.php');to display the info they put in, you'll need to save that info to the session, then use the HTML value="" attribute. Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155938 Share on other sites More sharing options...
NickG21 Posted January 8, 2007 Author Share Posted January 8, 2007 the only problem with me doing that is that ListInfo.php has no .css involved with it, it is just a plain form that i Include in headerImage.php which has all of the styles in it. what if i sent back to headerImage.php and made the 'step' = whatever it should with that particular page?plus i have all of the <?php echo '$variable' ?> in all of the text boxes and i set the values to "" if they don't pass validation. Those work correctly Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155941 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 What if? Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155944 Share on other sites More sharing options...
NickG21 Posted January 8, 2007 Author Share Posted January 8, 2007 [code]if(count($error) > 0){ header('Location: headerImage.php'); echo "<input type='hidden' value='' name='step'>"; echo "Please Correct Your Errors Before Proceeding";}ELSE{ include_once('headerImage.php');}}[/code]that works correctly to bring me back to the page if there are errors, however, it will not display the echo or redisplay the values of the variables that have been stored in the session. i would imagine it is because i am redisplaying the initial page that is included in headerImage.php, in this case ListInfo.php. any idea how i can get around this, because headerImage.php has the session stored in it and i am almost positive the variables are still saved. Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155947 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 did you try printing out the session to be POSITIVE? :-Pprint_r($_SESSION) Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155949 Share on other sites More sharing options...
NickG21 Posted January 8, 2007 Author Share Posted January 8, 2007 the variables are only saved if they pass through the validation, when the page is returned everything is reset.i thought putting all of the variables into a hidden field might work to keep them but it doesn't eitherforeach($_SESSION as $key => $value){ echo "<input type='hidden' value='" . $value . "' name='" . $key . "'>";} Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155959 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 I don't understand what you're saying. What is the problem? You want the information that DID pass validation to be saved in the session and put in hidden inputs? Why doesn't that work? Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155961 Share on other sites More sharing options...
NickG21 Posted January 8, 2007 Author Share Posted January 8, 2007 i want all of the information to be stored no matter what, if the information does pass it is just kept as is, but if there is other information that doesn't pass i want that form to reLoad with the good information still in the text fields and the fields with invalid input will just be blank. the user will then have to refill the information that was invalid. when the information is valid, i will move on to the next form. that part works fine, it is only if the info is invalid i can't Re-Post the good information back into the form because all of the variables are reset.i hope that is a little more clear Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155969 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 So save the information in the session, and print it out on the form using the html value="" Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155971 Share on other sites More sharing options...
alpine Posted January 8, 2007 Share Posted January 8, 2007 The easiest way is to run the validation on the same page as the form. Usually this is not a problem.Example:[code]<?php$complete = false;$empty_arr = array();foreach($_POST as $fieldname => $fieldvalue){ if(empty($fieldvalue)) { $empty_arr[] = $fieldname." was left empty"; } ${$fieldname} = $_POST[$fieldname];}if(!empty($empty_arr)){ echo "<ul><li>"; echo implode($empty_arr, '</li><li>'); echo "</li><ul>";}else{ // no empty fields, prosess posted values already defined as $fielnames $complete = true;}if($complete == false){echo <<<_HTML<form method="post" action="{$_SERVER['PHP_SELF']}"><p>Name:<br /><input type="text" name="name" value="$name" /></p><p>Email:<br /><input type="text" name="email" value="$email" /></p><p><input type="submit" name="submit" value="Send" /></p></form>_HTML;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-155972 Share on other sites More sharing options...
NickG21 Posted January 8, 2007 Author Share Posted January 8, 2007 i understand it might be easier to validate on the same form, but i am unaware of how to have my main site proceed and load the next form if the information is valid. Jesi, i cannot save the information into session variables and then redisplay the initial page, i thought it would just keep all the submitted data since the session was already opened but it clears all the values for every variable until you process on to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-156038 Share on other sites More sharing options...
alpine Posted January 8, 2007 Share Posted January 8, 2007 Example with sessions, jumping to another file upon success:[code]<?phpsession_start();if(isset($_POST['submit'])){$empty_arr = array();foreach($_POST as $fieldname => $fieldvalue){ if(empty($fieldvalue)) { $empty_arr[] = $fieldname." was left empty"; } ${$fieldname} = $_POST[$fieldname]; // just so that submitted values can be re-displayed in the form if another field value is missing $_SESSION[$fieldname] = ${$fieldname}; // also store value in a session in case no field values is missing in the end}if(!empty($empty_arr)){ echo "<ul><li>"; echo implode($empty_arr, '</li><li>'); echo "</li><ul>";}else{ header("location: next.php"); // and in next you fetch all current data from $_SESSION['fieldname'] // inside next.php you can put this as a test (uncomment it ofcource): // <? php // session_start(); // echo "<pre>"; // print_r($_SESSION); // echo "</pre>"; // ? > exit();}}echo <<<_HTML<form method="post" action="{$_SERVER['PHP_SELF']}"><p>Name:<br /><input type="text" name="name" value="$name" /></p><p>Email:<br /><input type="text" name="email" value="$email" /></p><p><input type="submit" name="submit" value="Send" /></p></form>_HTML;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-156142 Share on other sites More sharing options...
Xster Posted January 29, 2007 Share Posted January 29, 2007 hello guys,how to create a good validation..because mine is not so good..its still accepting any data entry (letter,symbol or number) but suppose to be [b]number[/b] or none...here's i'd post the image of my form..hope the image will help.p/s: im very new in php..so,i really need some guidence... Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-171607 Share on other sites More sharing options...
Xster Posted January 29, 2007 Share Posted January 29, 2007 Btw,this link...[url=http://www.badongo.com/pic/433848]http://www.badongo.com/pic/433848[/url]suppose to show you the image of my php..hope this will help... Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-171626 Share on other sites More sharing options...
anatak Posted January 29, 2007 Share Posted January 29, 2007 to validate against only numbers you need to use a regular expression (regex)here is a tutorial http://weblogtoolscollection.com/regex/regex.phpif you give us more detail we can help you build your regex.I think you try to enter hours and minutes into your formis the hour 1 written as a 1 or as 01 ?anatak Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-171654 Share on other sites More sharing options...
Xster Posted January 29, 2007 Share Posted January 29, 2007 aha,anatak thx 4 the msg..the hours is suppose written as 01 using format 24 hours not am/pm...am i clear o not?there's a button called 'NEXT' below the picture that i just mention before..btw anatak,how to build the regex? Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-171670 Share on other sites More sharing options...
Xster Posted January 29, 2007 Share Posted January 29, 2007 here's my code[code]<?phpif(!isset($_POST['submit'])){?><form action="" method="post"><table width="100%" cellpadding="10" cellspacing="0" border="0"><!--Step 3 : Select Time--><tr><td style="border-width:1px; border-color:#A8B2C6; border-style:solid;" class="body" colspan="2"><div style="font-size:18px; color:#007E8C; font-weight:bold;"><font color="#cccccc">3. </font>Select Time</div><br></td></tr><tr><td width="15%" class="body-facilities">From:</td><td class="body-facilities"> <input type="text" name="timeFrom" size="1" maxlength="2"> : <input type="text" name="timeFrom1" size="1" maxlength="2"> <sup style="color:#FF0000">eg: 08:00</sup></td></tr><tr><td class="body-facilities">To:</td><td class="body-facilities"> <input type="text" name="timeTo" size="1" maxlength="2"> : <input type="text" name="timeTo1" size="1" maxlength="2"> <sup style="color:#FF0000">eg: 23:00</sup></td></tr><tr><td class="body-facilities"><sub>Operating Hour:</sub></td><td class="body-facilities"><sub><?php echo $row_rs['fac_wkdayS'];?> to <?php echo $row_rs['fac_wkdayE'];?> (Monday to Friday)</sub><br><sub><?php echo $row_rs['fac_wkendS'];?> to <?php echo $row_rs['fac_wkendE'];?> (Saturday & Sunday)</sub></td></tr><tr><td colspan="2" align="right"><input type="submit" name="submit" value="Next"> <input type="hidden" name="fac_id" value="<?php echo $fac_id;?>"> </td></tr></table></form><?php}?></td></tr></table></td>[/code]again how to build and put the regex into this code and which line it was?i appreciate any help... Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-171676 Share on other sites More sharing options...
anatak Posted January 29, 2007 Share Posted January 29, 2007 $legit = ereg("^[0-9]{2,2}$", $time);you have to check two times. one for hours and ones for minutes.$legit will be true if the string $time is 2 numbers.hope this helps.anatak Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-172251 Share on other sites More sharing options...
Xster Posted January 30, 2007 Share Posted January 30, 2007 anyway thx anatak..i do understand the code that you've given..but which line should i put the code inside my php code?i put a long with php tags and nothing happened..and it still run'd like usual..sorry if i ask silly questions..rite now im trying and still got some error. Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-172433 Share on other sites More sharing options...
anatak Posted February 27, 2007 Share Posted February 27, 2007 Xster I noticed you write <form action="" method="post">so you in the page where you receive the information from you form you have to do something like$time = $_POST['timeFrom']$legit = ereg("^[0-9]{2,2}$", $time);if ($legit==TRUE){time is correctly formatted}else{time is not correctly formatted}I hope this helpsanatak Quote Link to comment https://forums.phpfreaks.com/topic/33349-validation-on-all-forms/#findComment-195082 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.