Guteman Posted August 3, 2006 Share Posted August 3, 2006 Hey All,Im doing my first PHP project and I have hit a screaming halt with an annoying issue. Im creating a client registration system for my web development company. My problem is, I have if statements used to if for example "client name" is left blank, It sends an error message back saying "You did not enter a Client First Name, go back and try again." When I click back, it clears the form in IE, but not in firefox. What has to be done so it will work in IE? Thanks ahead of time.Paul G. Quote Link to comment https://forums.phpfreaks.com/topic/16463-user-registration-issues/ Share on other sites More sharing options...
SharkBait Posted August 3, 2006 Share Posted August 3, 2006 Pretty much your form field should look like this:[code]Name: <input type="text" size="20" name="cName" value="<?php if (isset($_POST['cName'])) echo $_POST['cName']; ?>" />Email: <input type="text" size="20" name="cEmail" value="<?php if(isset($_POST['cEmail'])) echo $_POST['cEmail'];?>" />[/code]If it works in Firefox and not in IE, might be a silly HTML error. Firefox seems to be smart enough to fix them on the fly, and IE isnt... or thats my experience anyway.. Quote Link to comment https://forums.phpfreaks.com/topic/16463-user-registration-issues/#findComment-68661 Share on other sites More sharing options...
bltesar Posted August 3, 2006 Share Posted August 3, 2006 When you receive the values via GET or POST, store them in a session variable, say an array. [code]//get all your POSTed information and store it in a session variable(an array)foreach($_POST as $key=>$value){ $sent_values[$key]=$value;}$_SESSION['sent_values']=$sent_values;[/code]then if invalid data is received, you can send the client back automatically using[code]header('Location:http://mydomain.com/form_page.php?error=name'); //redirects back to form pageexit(); //this must-have prevents subsequent code from running[/code]on your form page, get the sent_values session variable and load your form inputs with the values[code]//check for existence of session variable holding sent valuesif(isset($_SESSION['sent_values'])){ $sent_values=$_SESSION['sent_values']; //create variables from the array populated with the sent values foreach($sent_values as $key=>$value) { $$key=$value; }}//you can use the querystring appended at the end of the URL to print the error messageif($_GET['error']=='name'){echo 'name is missing');[/code]Then your form input elements look like this:<input type="text" name="input_1" value="<?PHP echo $input_1;?>">you might want to destroy the SESSION variable so that the form clears on reload:[code]$_SESSION['sent_values']=array();unset($_SESSION['sent_values']);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16463-user-registration-issues/#findComment-68663 Share on other sites More sharing options...
SharkBait Posted August 3, 2006 Share Posted August 3, 2006 Why store them in a session when they are already stored in the $_POST[]?This is how I do it when I make forms and want them to echo the fields that have already been filled in so they don't have to do it again.[code]<?phpif(isset($_POST['submit'])) { $errMsg = ""; // String to store error messages to be displayed later... // Form has been submitted use $_POST[] to get the values if(!empty($_POST['cName'])) { // Name was not left blank $name = $_POST['cName']; } else { $errMsg .= "<li>You cannot leave the Name field blank.</li\n"; } if($errMsg == "") { // Do your think there } else { // There was a submission error echo "There have been errors with your submission, they are: <br /> <ul>{$errMsg}</ul>\n"; } }// Display Form and check to see if the $_POST[] variables are already set?><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">Name <input type="text" name="cName" value="<?php if(isset($_POST['cName'])) echo $_POST['cName'];?>" /><input type="submit" value="Submit" name="submit" /></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16463-user-registration-issues/#findComment-68703 Share on other sites More sharing options...
bltesar Posted August 3, 2006 Share Posted August 3, 2006 the SESSION variable is only needed if the form and validation are done on different pages. I assumed that to be the case because the original question indicated that invalid data would give a 'go back' method. I sometimes use a hidden validation page that redirects the user depnding on success/failure of input. That way, data cannot be inadvertantly resubmitted by using the back button. Quote Link to comment https://forums.phpfreaks.com/topic/16463-user-registration-issues/#findComment-68708 Share on other sites More sharing options...
Guteman Posted August 3, 2006 Author Share Posted August 3, 2006 well both of you are right. I like the idea of using sessions, but then again $_POST already has it stored. I originally had this on 2 seperate pages, which would need sessions. I find it easier (since im no PHP guru) to just use the $_POST in the value and make it one page.Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/16463-user-registration-issues/#findComment-68710 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.