Advertisement

04.22.2008 at 05:48AM PDT, ID: 23342673
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Does the validate url method still exist inside PEAR?

Asked by mickeden in PHP Scripting Language

Tags: ,

Hi experts
I'm currently trying to get my head round OOP, using the Sitepoint book The PHP Anthology. Part of the book deals with PEAR and one of the examples I'm playing with(code posted below)  generates this error:
Fatal error: Call to undefined method Validate::url() in C:\Program Files\xampp\htdocs\websites\sandbox\sitepoint\phpant2-download\code_archive\chapter_03\examples\pear_validate.php_phpd_tmp21.php on line 33
I've trawled the PEAR site and the only reference i can find to this method is dated in 2002, and no reference to a typo is to be found on the book errata site. Can any body tell me if I've got a problem with my PEAR installation or if the book is wrong...if i change url to uri (in the call) the error is not generated - but neither does it validate a url properly)


Any advice would be much appreciated
regards
Mick
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
<?php
// to remove the E_STRICT errors created by PEAR::Validate
error_reporting(E_ALL);
// Include Magic Quotes stripping script
require_once 'strip_quotes.php';
// Include PEAR::Validate
require_once 'Validate.php';
 
// Initialize errors array
$errors = array('name' => '', 'email' => '', 'url' => '');
// If the form is submitted...
if (isset($_POST['submit']))
{
  // Define the options for formatting the name field
  $name_options = array(
      'format'     => VALIDATE_ALPHA . VALIDATE_SPACE,
      'min_length' => 5
  );
 
  // Validate name
  if (!Validate::string($_POST['name'], $name_options))
  {
    $errors['name'] = ' class="error"';
  }
 
  // Validate email
  if (!Validate::email($_POST['email']))
  {
    $errors['email'] = ' class="error"';
  }
 
  // Validate url
  if (!Validate::url($_POST['url']))
  {
    $errors['url'] = ' class="error"';
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>PEAR::Validator</title>
    <style type="text/css">
      form.userinfo {
        font-family: verdana;
        font-size: 12px;
        width: 30em;
      }
 
      form.userinfo h1 {
        font-weight: bold;
        font-size: 12px;
      }
 
      form.userinfo div {
        clear: both;
        margin: 5px 10px;
      }
 
      form.userinfo label {
        float: left;
      }
 
      form.userinfo span {
        float: right;
      }
 
      .error {
        color: red;
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <form class="userinfo" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
      <?php
        $name = isset($_POST['name']) ? $_POST['name'] : '';
        $email = isset($_POST['email']) ? $_POST['email'] : '';
        $url = isset($_POST['url']) ? $_POST['url'] : '';
      ?>
      <h1>Enter your details</h1>
      <div>
        <label<?php echo $errors['name']; ?>>Name:</label>
        <span>
          <input type="text" name="name" value="<?php echo $name; ?>" />
        </span>
      </div>
      <div>
        <label<?php echo $errors['email']; ?>>Email:</label>
        <span>
          <input type="text" name="email" value="<?php echo $email; ?>" />
        </span>
      </div>
      <div>
        <label<?php echo $errors['url']; ?>>Website:</label>
        <span>
          <input type="text" name="url" value="<?php echo $url; ?>" />
        </span>
      </div>
      <div>
        <span>
          <input type="submit" name="submit" value="send" />
        </span>
      </div>
    </form>
  </body>
</html>
 
Loading Advertisement...
 
[+][-]04.22.2008 at 08:09AM PDT, ID: 21411867

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: PHP AND PEAR, Fatal error: Call to undefined method Validate::url() in C:\Program Files\xampp\htdocs\websites\sandbox\sitepoint\phpant2-download\code_archive\chapter_03\examples\pear_validate.php_phpd_tmp21.php on
Sign Up Now!
Solution Provided By: akshah123
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628