473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use what the function returns?

Hi

I am a newbie and struggling with my guestbook validation process.
I have found the following function online to check the length of a
form field.

<?php
function checkLength($string, $min, $max) {
$length = strlen ($string);
if (($length < $min) || ($length > $max)) {
return FALSE;
} else {
return TRUE;
}
}
?>

Now below is the area in my code where I have to fit what that function
returns but I can't do it. The "Text" field is the one that has to be
checked for a certain length (Like $min = 1, $max = 100).I would like
to point to the error.html file if checkLength returns false.

$Text = $_POST['Text'] ;
$email = $_POST['email'] ;
$name = $_POST['name'] ;

if (empty($name) || empty($email)) {
header( "Location: error.html" );

}
else
{

//The fields are entered in the database here if it all goes fine.
Thanks a lot

Patrick

Jul 17 '05 #1
8 1676
varois83 wrote:
Now below is the area in my code where I have to fit what that
function returns but I can't do it. The "Text" field is the one that
has to be checked for a certain length (Like $min = 1, $max = 100).I
would like to point to the error.html file if checkLength returns
false.

$Text = $_POST['Text'] ;
$email = $_POST['email'] ;
$name = $_POST['name'] ;

if (empty($name) || empty($email)) {
header( "Location: error.html" );


if (!checkLength($Text, 1, 100) || empty($name) || empty($email)) {
....
}

BTW, there's more to form validation than used in this code (per example, it
will allow a single white space character to pass as a valid email address),
but you will probably get to this when you have learned more about PHP.
JW

Jul 17 '05 #2
I noticed that Message-ID: <41**********************@news.euronet.nl>
from Janwillem Borleffs contained the following:
if (!checkLength($Text, 1, 100) || empty($name) || empty($email)) {

Bit unfriendly sending people to an error page if they type too much.
Still I suppose you have your reasons. Consider using some Javascript
in addition to the PHP code to give the user instant feedback that they
are over the limit
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
On Sun, 23 Jan 2005 23:14:54 +0000, Geoff Berrow <bl@ckdog.co.uk> wrote:
I noticed that Message-ID: <41**********************@news.euronet.nl>
from Janwillem Borleffs contained the following:
if (!checkLength($Text, 1, 100) || empty($name) || empty($email)) {


Bit unfriendly sending people to an error page if they type too much.
Still I suppose you have your reasons. Consider using some Javascript
in addition to the PHP code to give the user instant feedback that they
are over the limit


Or the maxlength attribute if it's an <input>. Shame there isn't such an
attribute on <textarea> though.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4
Hi

JB

God I tried everything for 2 hours, it's almost not fair.A pair of
parenthesis did me in.
Look at what I had that came the closest.:

if (empty($name) || empty($email) || (!checkLength($Text, 1, 100))) {

I also understand that there is a lot more to validation than that but
practice will make perfect.

Thanks so much for your help JB it's working now.

Geoff

Bit unfriendly sending people to an error page if they type too much.
Still I suppose you have your reasons. Consider using some Javascript
in addition to the PHP code to give the user instant feedback that they
are over the limit.

Just playing around with the code at this time Geoff, trying to use
only PHP at this point. I am going to create a page that tells people
that use more than 100 characters not to do so.
Thanks a lot guys

Patrick

Jul 17 '05 #5
JW

I spoke too fast in my previous post and tested what you said about the
code allowing a single space. It did!
How do you fix that?

Thanks again

Patrick

Jul 17 '05 #6
varois83 wrote:
JW

I spoke too fast in my previous post and tested what you said about the
code allowing a single space. It did!
How do you fix that?

Thanks again

Patrick


regular expressions
Jul 17 '05 #7
eregi()

http://us2.php.net/manual/en/function.eregi.php
It takes time to master.

Jul 17 '05 #8
Thanks again guys will get on it right away.

Patrick

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
9
by: Marek Lewczuk | last post by:
Hello, I'm moving out from MySQL to PostgreSQL and there are some function which are not supported in PG so I'm trying to write my own functions. Currently I have big problem with function IF(),...
8
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If...
11
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to...
17
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
4
by: ranjmis | last post by:
Hi all, I have come across a piece of code wherein a function returns a function pointer as it seems to me but not very clear from the prototype. As shown below - although return type is void...
2
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
7
by: jknaty | last post by:
I'm trying to create a function that splits up a column by spaces, and I thought creating a function that finds the spaces with CHARINDEX and then SUBSTRING on those values would an approach. I...
11
by: Antoninus Twink | last post by:
What's the correct syntax to define a function that returns a pointer to a function? Specifically, I'd like a function that takes an int, and returns a pointer to a function that takes an int and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.