|
Free
PHP Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
|||||
PHP Tutorials |
||||||
|
A PHP Function to check for blank Textboxes
If you remember the script that we wanted to create earlier it was this:
So we want to check that the textbox doesn't just contain this "". There has to be something in it, like "Bill Gates". Here's a script that does all three items on our list: <?PHP $user_text = trim("Bill Gates"); display_error_message($user_text); function display_error_message($user_text) { if ($user_text
== "") { ?> Try it out. When you run the script, you should find that Text OK prints. Now change this line: $user_text = trim("Bill Gates"); to this: $user_text = trim("");
Try the script out. But the point is, that we're using the same function
to check for blank text boxes. We're not writing the same code over
and over. Just call our one function as and when needed. In the next part, we'll see how to get values back out of functions. <-- Back One Page Move on to the Next Part --> |