Search the Community
Showing results for tags 'validate'.
-
Hello sorry if the question is not proper / clear. which one of these two ways is better to validate. <?php # using a variable $query = $_POST['query']; $ok = FALSE; if ( $query = 'php' ){ $ok = TRUE;} else { $ok = FALSE;} if ( $ok = TRUE; ){ // more code } # direct way $query = $_POST['query']; if ( $query = 'php' ){ // more code } else { // more codes } ?> Thanks in advance.
-
Hello Guys... I need help about my validate scripts... $(document).ready(function(){ //Validation jQuery.validator.addMethod('validIPurl', function(value) { var ip = '^([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])$'; var URL = /^(http|https)?:\/\/[a-zA-Z0-9-\.]+\.[a-z]{2,4}/; //HOW TO JOIN AND VALIDATE BOTH VARIABLE IP AND URL???? } }, 'Invalid Address'); //if(/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i) $(".myfirstform").validate( { rules: { ip: { validIPurl: true } }, ); }, I use jquery.validate javascripts to validate user input.. I also try to create if..else to join IP and URL but the control statement not working Hope you guys can help for the solution...
- 1 reply
-
- jquery
- javascripts
-
(and 1 more)
Tagged with:
-
Hi I'm trying to post and validate a form but it doesn't seem to work and it doean't display any errors Here's the code <?php include("config.php"); session_start(); ?> <?php // define variables and initialize with empty values $rateErr = $comErr = ""; $rating = $comment = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_POST["rating"] == "") { $rateErr = "Rate the app"; } else { $rating= $_POST["rating"]; } if (empty($_POST["comment"])) { $comErr = "Missing"; } else { $comment = $_POST["comment"]; } if ($rateErr == "" && $comErr == "") { try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO reviews (rating, content, appID, user) VALUES(:rating, :comment, :appID, :username)"; $stmt = $con->prepare( $sql ); $stmt->bindValue( ":rating", $rating); $stmt->bindValue( ":comment", $comment); $stmt->bindValue( ":appID", $_GET['id']); $stmt->bindValue( ":username", $_SESSION['username']); $stmt->execute(); return "Submitted successfully"; }catch( PDOException $e ) { return $e->getMessage(); } } } ?> <html> <head> </head> <body> <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <select name="rating"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <span class="error"><?php echo $rateErr;?></span> <br /> <textarea rows="4" cols="50" name="comment" value="<?php echo htmlspecialchars($comment);?>"> Enter text here...</textarea> <span class="error"><?php echo $comErr;?></span> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
-
Hi. I am new. I don't know how to validate certain data like emai, web site and numeric value. Here is my code which is work fine. Below is my code. Pls Help me add.php <?php include_once '../inc/header.php'; ?> <Script Language="javascript"> function change_action() { var frm_obj=document.getElementById("frm"); frm_obj.action="data.php"; } </Script> <form action="" method="POST" id="frm" > <table class="" align="center" cellpadding="4" cellspacing="1"> <tr> <td><label class="lbl">ID </label></td> <td><label class="lbl">: </label></td> <td><input type="text" name="id" id="id" readonly="" class="txt"></td> </tr> <tr> <td><label class="lbl">Name </label></td> <td><label class="lbl">: </label></td> <td><input type="text" name="name" id="name" class="txt"></td> </tr> <tr> <td><label class="lbl">Address </label></td> <td><label class="lbl">: </label></td> <td><textarea name="address" id="address" class="txt" rows="5" cols="40"></textarea></td> </tr> <tr> <td><label class="lbl">Tel</label></td> <td><label class="lbl">: </label></td> <td><input type="text" name="tel" id="tel" class="txt"></td> </tr> <tr> <td><label class="lbl">Fax</label></td> <td><label class="lbl">: </label></td> <td><input type="text" name="fax" id="fax" class="txt"></td> </tr> <tr> <td><label class="lbl">Email</label></td> <td><label class="lbl">: </label></td> <td><input type="text" name="email" id="email" class="txt"></td> </tr> <tr> <td><label class="lbl">Web site</label></td> <td><label class="lbl">: </label></td> <td><input type="text" name="website" id="website" class="txt"></td> </tr> <tr> <td><label class="lbl">Type</label></td> <td><label class="lbl">: </label></td> <!--<td><input type="text" name="type" id="type" class="txt"></td>--> <td> <SELECT NAME=type id="type"> <OPTION VALUE=0>Choose <?php $sql="SELECT * FROM bk_parameter where type='typcs' order by id"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { $typename=$row["name"]; echo "<OPTION VALUE=\"$typename\">".$typename.'</option>'; } ?> </SELECT> </td> </tr> <tr> <td></td> <td></td> <td><input type="submit" value="submit" name="submit" class="btn" onclick="change_action()"> <input type="submit" value="back" name="back" class="btn" onclick="change_action()"></td> </tr> </table> </form> <?php include_once '../inc/footer.php'; ?> data.php <?php include_once '../inc/header.php'; //insert into table if (isset($_POST['submit']) && $_POST['submit'] != "" ) { $name = ($_POST["name"]); $address = ($_POST["address"]); $tel = ($_POST["tel"]); $fax = ($_POST["fax"]); $email = ($_POST["email"]); $website = ($_POST["website"]); $type = ($_POST["type"]); try { $sql="INSERT INTO bk_customer (name,address,tel,fax,email,website,type) VALUES ('$name','$address','$tel','$fax','$email','$website','$type')"; $result = mysqli_query($con,$sql) ; header("Location:index.php"); exit(); } catch (Exception $ex) { echo $e->getMessage() . "\n"; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); exit(); } } //mysqli_close($con); // update table if (isset($_POST['update']) && $_POST['update'] != "" ) { $id= ($_POST["id"]); $name = ($_POST["name"]); $address = ($_POST["address"]); $tel = ($_POST["tel"]); $fax = ($_POST["fax"]); $email = ($_POST["email"]); $website = ($_POST["website"]); $type = ($_POST["type"]); try { $sql="UPDATE bk_customer SET name='$name',address='$address', tel='$tel',fax='$fax'," . "email='$email', website='$website',type='$type' WHERE id='$id'"; $result = mysqli_query($con,$sql) ; header("Location:index.php"); } catch (Exception $ex) { echo $e->getMessage() . "\n"; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); exit(); } } // update record if (isset($_POST['delete']) && $_POST['delete'] != "" ) { $id=$_POST["id"]; try { $sql="DELETE FROM bk_customer WHERE id='$id'"; $result = mysqli_query($con,$sql) ; header("Location:index.php"); } catch (Exception $ex) { echo $e->getMessage() . "\n"; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); exit(); } } // back to index.php if (isset($_POST['back']) && $_POST['back'] != "" ) { header("Location:index.php"); }
-
Hi all, I am trying to validate a form, but run into some troubles... Full Name This works up until a space is present then fails, any suggestions? // # Fullname if (isset($_POST["Fullname"])){ $fnop = $_POST["Fullname"]; if (ctype_alpha($fnop)) { echo "</BR>PASSED! : FULLNAME : $fnop"; } else { echo "</BR>FAILED! : FULLNAME : $fnop"; } }; Test case: INPUT: 123456789 | OUTPUT: FAILED; INPUT: ABCD1234 | OUTPUT: FAILED; INPUT: AbCdEfGh | OUTPUT: PASSED; INPUT: AbC<Space>DeF | OUTPUT: FAILED; Phone number This works up until a 0 is in the number and then fails, any suggestions? // # Contact Num if (isset($_POST["Phone"])){ $phoneop = $_POST["Phone"]; if (filter_var($phoneop, FILTER_VALIDATE_INT)) { echo "</BR>PASSED! : PHONE : $phoneop"; } else { echo "</BR>FAILED! : PHONE : $phoneop"; } }; Test case: INPUT: 123456789 | OUTPUT: PASSED; INPUT: ABCD1234 | OUTPUT: FAILED; INPUT: AbCdEfGh | OUTPUT: FAILED; INPUT: 0432666777 | OUTPUT: FAILED; Kind regards and advance thanks.
-
hi, count number of words in textbox and then validate that the number of words should be between 400 to 1000. i googled alot... but didn't get an correct answer.... ??? need help!!! with regards, jasmeet.
-
could someone look at this and see if they can tell what I am doing wrong? please and thanks <?php $chkerrors = FALSE; if (!filter_has_var(INPUT_POST, "fName"));{ echo " please enter a value "; $ckerrors = TRUE; } if (!filter_has_var(INPUT_POST, "lName"));{ echo " please enter a value "; $ckerrors = TRUE; } if (!filter_has_var(INPUT_POST, "city"));{ echo " please enter a value "; $ckerrors = TRUE; } if (!filter_has_var(INPUT_POST, "state"));{ echo " please enter a value "; $ckerrors = TRUE; } if (!filter_has_var(INPUT_POST, "zipCode"));{ echo " please enter a value "; $ckerrors = TRUE; } $fName = filter_input(INPUT_POST, "fName"); $lName = filter_input(INPUT_POST, "lName"); $city = filter_input(INPUT_POST, "city"); $state = filter_input(INPUT_POST, "state"); $zipCode = filter_input(INPUT_POST, "zipCode"); if($chkerrors == FALSE) { echo <<<HERE <h3> Hi there, $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year. <br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br />I hope that you have a great summer in $city. <br /></h3> HERE; } ?>
-
Continuing my posting of security-related functions in this section, I've decided to post this one up. I've posted a basic version of the RegExp previously, to which Psycho gave me some good feedback. Thus, the current function was born: // Define the flags used for validating passwords. define ('SF_VALIDATE_PASS_LOWER', 1); define ('SF_VALIDATE_PASS_UPPER', 2); define ('SF_VALIDATE_PASS_NUMERICAL', 4); define ('SF_VALIDATE_PASS_SPECIAL', ; define ('SF_VALIDATE_PASS_ALL', 15); /** * Validates the password according to the flags and mininum length given. * * Returns true if the password matches the constraints, or false if it fails. * * Default minimum length is 8 characters, and all flags activated. * * @author Christian Fagerheim (Fagerheim Software) * @link www.fagsoft.no * @license Creative Commons Attribution-ShareAlike 3.0. http://creativecommons.org/licenses/by-sa/3.0/. * * @param string $password * @param int[optional] $minLength * @param int[optional] $flags * * @return bool */ function validatePassword ($password, $minLength = 8, $flags = SF_VALIDATE_PASS_ALL) { // Make sure we got a valid minimum length. if (!is_int ($minLength) || $minLength < 0) { trigger_error ('Minimum length must be a positive integer', E_USER_ERROR); } // Create the constraints for the password. $passReg = ''; if ($flags & SF_VALIDATE_PASS_LOWER) { $passReg .= '(?=.*[a-z])'; } if ($flags & SF_VALIDATE_PASS_UPPER) { $passReg .= '(?=.*[A-Z])'; } if ($flags & SF_VALIDATE_PASS_NUMERICAL) { $passReg .= '(?=.*\\d)'; } if (false && $flags & SF_VALIDATE_PASS_SPECIAL) { $special = preg_quote (',.;:"\'!?*(){}[]/^§|#¤%&_=<>@£$€ +-', '/'); $passReg .= "(?=.*[$special])"; } // Add the minimum length requirement. $passReg .= '.{'.$minLength.',}'; // Check that the password matches the constraints, and return a boolean. if (!preg_match ("/^$passReg\\z/u", $password)) { return false; } return $password; }