Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'strlen'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. I am trying to confirm entries in the form below using strlen but am stymied by a strange bug/error - in check for entries in subject and message fields else if((strlen($_POST['subject']) == 0) || (strlen($_POST['message']) == 0)) the first condition works perfectly ($length=0) but strlen($_POST['message'] returns $messagelen=5 or more even when nothing is entered?! When you first click in the textarea the cursor positions beyond the start point - which is probably causing the error, but why? Thank you for any help. <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_POST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ($mailcheck==FALSE) { $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "<a href='$url'>Invalid form entry.<br><br> Please click here to return to form and retry.</a>"; } // check for entries in subject and message fields else if((strlen($_POST['subject']) == 0) || (strlen($_POST['message']) == 0)) { $url = htmlspecialchars($_SERVER['HTTP_REFERER']); $length = strlen($_POST['subject']); $messagelen = strlen($_POST['message']); echo "<a href='$url'>Please fill in all fields. " . $length . $messagelen . "<br><br> Please click here to return to form and retry.</a>"; } else {//send email $email = $_POST['email'] ; $subject = $_POST['subject'] ; $message = $_POST['message'] ; mail("me@example.com", "Subject: $subject", $message, "From: $email" ); $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "Thank you for using our mail form"; echo "<a href='$url'>Click here to return</a>"; } } else {//if "email" is not filled out, display the form echo "<p><b>If you have any questions and wish to contact us,<br /> please fill in the form below.</b></p><br> <form method='post' action='formpage.php'> <fieldset><legend>Your Contact Information</legend> Email: <input name='email' type='text' tabindex='1'><br> Subject: <input name='subject' type='text' tabindex='2'><br> Message:<br> <textarea name='message' rows='7' cols='40' tabindex='3'> </textarea><br> <input type='submit' id='submit' tabindex='4'> </fieldset> </form>"; } ?>
×
×
  • Create New...