Boo-urns Posted January 14, 2009 Share Posted January 14, 2009 When processing a form with double quotes and the validation fails the value is just the '\' that is added in. However when I echo it out right after escaping it it displays properly. My question is how would you put their inputted value back? (Everything besides double quotes returns correctly to the form when validation fails) Posting variable and running function <?php // inside the form processing $fName = $db->check_n_escape($_POST['fName'], 'first name'); Function in the db class <?php // check n escape function in the db class function check_n_escape($str, $checkName) { if($str == NULL) { $this->fieldError = 1; $this->fieldErrMsg .= ($this->fieldErrMsg != NULL) ? $checkName . ", " : $this->fieldErrMsgStart . $checkName . ", "; } else { return $this->escape_str($str); } } function escape_str($str) { // escaping strings if(get_magic_quotes_gpc()) {$str = stripslashes($str);} if(function_exists("mysql_real_escape_string")) {$str = mysql_real_escape_string($str);} else {$str = addslashes($str);} return $str; } ?> Or is there a better way? Thanks for your help! -Corey Quote Link to comment https://forums.phpfreaks.com/topic/140825-solved-escaped-string-value-disapears/ Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 How are you displaying the value? Ken Quote Link to comment https://forums.phpfreaks.com/topic/140825-solved-escaped-string-value-disapears/#findComment-737120 Share on other sites More sharing options...
Boo-urns Posted January 14, 2009 Author Share Posted January 14, 2009 I haven't put in a stripslashes function yet but I'm just outputting it to the field. <input type="text" name="fName" id="fName" value="<?= $fName; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/140825-solved-escaped-string-value-disapears/#findComment-737146 Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 You need to use the htmlentities function when displaying the data in the value attribute or the double quote in the data will end the value. If you had looked at the generated source of the form, you would have seen something like: <input type="text" name="fName" id="fName" value="this string has a " in it /> if the value of $fName had been 'this string has a " in it' You need to use: <input type="text" name="fName" id="fName" value="<?php echo htmlentities(stripslashes($fName),ENT_QUOTES); ?>" /> Ken Quote Link to comment https://forums.phpfreaks.com/topic/140825-solved-escaped-string-value-disapears/#findComment-737160 Share on other sites More sharing options...
Boo-urns Posted January 14, 2009 Author Share Posted January 14, 2009 That worked perfectly! Thanks Ken! -Corey Quote Link to comment https://forums.phpfreaks.com/topic/140825-solved-escaped-string-value-disapears/#findComment-737169 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.