function calls

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
twb
Forum Commoner
Posts: 27
Joined: Thu Jan 06, 2005 4:39 pm

function calls

Post by twb »

Hi
I have a problem that I would appreciate some help on. I am calling a function that checks 3 things 1)If the textbox is empty, if its a valid date format and if its a valid date. The last two parts of the function work however the 1st part that checks if the text box has fields in it dosen't. The data entered is through a text box:
The function call is as:

Code: Select all

<?php 
if(!empty($_POST&#1111;'txtSearch_from']))&#123; 
  $error = ValidateText($_POST&#1111;'txtSearch_from']); 
  if(!empty($error)) 
     &#123; echo $error,'... For Search_From textbox'; &#125;
    &#125;
?>
the function is as follows:

Code: Select all

function ValidateText($date)&#123;
  $msg = " ";
  if(empty($date))&#123; echo 'test';
  $msg .= (!empty($msg)) ? '<br>' : '';;
  $msg .= 'Text box is empty';
  return $msg;
  echo'<br>';
  exit();
 &#125;
 
if(!ereg('^(&#1111;0-9]&#123;2&#125;)/(&#1111;0-9]&#123;2&#125;)/(&#1111;0-9]&#123;4&#125;)$',$date,$parts))&#123;
   $msg .= (!empty($msg)) ? '<BR>': '';		
    $msg .= "Invalid birthdate format entry enter dd/mm/yyyy";
    return $msg;
     echo'<br>';
    exit();
   &#125;
if(!checkdate ($parts&#1111;2],$parts&#1111;1],$parts&#1111;3]))&#123;
  $msg = " ";
  $msg .= (!empty($msg)) ? '<BR>': '';		
  $msg .= "The date of birth is invalid. Check that month is between 1-12
	and day is valid for that month.";
   return $msg;
   echo '<br>';
   exit();
   &#125; 
&#125;
I hope I explained this well enough, if anymore info is needed let me know
Thanks in advance
Twb
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the passed variable may not be entirely empty.. try using trim() on it when you start using it inside the function.
twb
Forum Commoner
Posts: 27
Joined: Thu Jan 06, 2005 4:39 pm

function calls

Post by twb »

Thanks for the reply
I tried the trim..didn't seem to make a difference..hmmm
I dosen,t even call the function untill there is something in the text box..which defeats the purpose
I want to be able to leave the text input box empty that way when I submit with a blank field, i will be prompted "That the text box is empty"
twb
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. if you only run the code when the field isn't empty, and your first block will only work if it is empty, then yeah.. it won't work.
twb
Forum Commoner
Posts: 27
Joined: Thu Jan 06, 2005 4:39 pm

function calls

Post by twb »

What I ended up doing was creating a action variable to check if the text boxes were empty

Code: Select all

if (strtoupper($action) == 'CHECK') &#123;
  if(empty($txtSearch_from) or empty($txtSearch_to))&#123;
  	$msg .= (!empty($msg)) ? '<BR>': '';		
	$msg .= "Missing Required Fields"; &#125;//close if

&#125;//CLOSE IF
thanks
twb
Post Reply