本文整理汇总了PHP中UserData::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP UserData::getErrors方法的具体用法?PHP UserData::getErrors怎么用?PHP UserData::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserData
的用法示例。
在下文中一共展示了UserData::getErrors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
$invalidUser = array("userName" => "Thugnificent", "picture" => "../images/thugnificent.jpg", "firstName" => "Otis", "lastName" => "Jenkins", "address" => "123 Thug Lane", "neighborhood" => "Woodcrest", "dateOfBirth" => "1989-01", "gender" => "male", "comedy" => "checked", "email" => "thugnasty.gmail.com", "phone" => "(210) 555 - 5555", "url" => "https://otis_jenkins/facebook.com");
$userDataTest11 = new UserData($invalidUser);
$test2 = empty($userDataTest11->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for email is: " . $userDataTest11->getError('email') . "<br>";
echo "The object is: {$userDataTest11}<br>";
?>
<h2>It should have an error when the email isnt in the format (xxx) xxx - xxxx</h2>
<?php
$invalidUser = array("userName" => "Thugnificent", "picture" => "../images/thugnificent.jpg", "firstName" => "Otis", "lastName" => "Jenkins", "address" => "123 Thug Lane", "neighborhood" => "Woodcrest", "dateOfBirth" => "1989-01", "gender" => "male", "comedy" => "checked", "email" => "thugnasty@gmail.com", "phone" => "2105555555", "url" => "https://otis_jenkins/facebook.com");
$userDataTest12 = new UserData($invalidUser);
$test2 = empty($userDataTest12->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for phone is: " . $userDataTest12->getError('phone') . "<br>";
echo "The object is: {$userDataTest12}<br>";
?>
<h2>It should have an error when the url isnt in the format http:// or https://text.com</h2>
<?php
$invalidUser = array("userName" => "Thugnificent", "picture" => "../images/thugnificent.jpg", "firstName" => "Otis", "lastName" => "Jenkins", "address" => "123 Thug Lane", "neighborhood" => "Woodcrest", "dateOfBirth" => "1989-01", "gender" => "male", "comedy" => "checked", "email" => "thugnasty@gmail.com", "phone" => "(210) 555 - 5555", "url" => "otis_jenkins/facebook.com");
$userDataTest13 = new UserData($invalidUser);
$test2 = empty($userDataTest13->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for url is: " . $userDataTest13->getError('url') . "<br>";
echo "The object is: {$userDataTest13}<br>";
?>
</body>
</html>
示例2: implode
<?php
include_once "../models/UserData.class.php";
?>
<h2>It should create a valid UserData object when all input is provided</h2>
<?php
$validTest = array("userName" => "josht1234", "password" => "Green123", "confirmedpw" => "Green123", "email" => "josh@gmail.com", "dob" => "2015-12-12", "hockUser" => "mop", "color" => "#00FF00", "gender" => "male");
$s1 = new UserData($validTest);
echo "{$s1}<br>";
$test2 = empty($s1->getErrors()) ? '' : 'Failed: It should not have errors when valid input is provided<br>';
echo $test2;
if ($test2 != "") {
echo implode("|", $s1->getErrors());
}
?>
<h2>It should extract the parameters that went in</h2>
<?php
$props = $s1->getParameters();
print_r($props);
?>
<h2>Here is an example of a bunch of bad input and all the errors it will throw</h2>
<?php
$validTest = array("userName" => "as asdfioj \$", "password" => "green", "confirmedpw" => "green123", "email" => "", "dob" => "", "hockUser" => "", "color" => "#00FF00", "gender" => "");
$s1 = new UserData($validTest);
$props = $s1->getParameters();
print_r($props);
echo "<br>";
echo implode("<br>", $s1->getErrors());
示例3: array
<h2>It should have an error when the phone number is invalid</h2>
<?php
$invalidPhoneTest = array("phone" => "abc-def-ghij");
$s12 = new UserData($invalidPhoneTest);
$test12 = empty($s12->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test12;
echo "The error for phone is: " . $s12->getError('phone') . "<br>";
echo "The object is: {$s12}<br>";
?>
<h2>It should have an error when the favorite color is empty</h2>
<?php
$invalidFavColorTest = array("fav_color" => "");
$s13 = new UserData($invalidFavColorTest);
$test13 = empty($s13->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test13;
echo "The error for fav_color is: " . $s13->getError('fav_color') . "<br>";
echo "The object is: {$s13}<br>";
?>
<h2>It should have an error when the favorite color is invalid</h2>
<?php
$invalidFavColorTest = array("fav_color" => "#xyz123");
$s14 = new UserData($invalidFavColorTest);
$test14 = empty($s14->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test14;
echo "The error for fav_color is: " . $s14->getError('fav_color') . "<br>";
echo "The object is: {$s14}<br>";
?>
</body>
</html>