當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserData::getErrors方法代碼示例

本文整理匯總了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>
開發者ID:raroseman,項目名稱:cs4413-Hoodflix,代碼行數:30,代碼來源:UserData_test.php

示例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());
開發者ID:Trivette,項目名稱:cs4413,代碼行數:30,代碼來源:UserData_tests.php

示例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>
開發者ID:mr-augustine,項目名稱:sensor-data-repo,代碼行數:31,代碼來源:UserData_tests.php


注:本文中的UserData::getErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。