Page 1 of 1

function calls

Posted: Mon Jan 17, 2005 2:38 pm
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

Posted: Mon Jan 17, 2005 2:45 pm
by feyd
the passed variable may not be entirely empty.. try using trim() on it when you start using it inside the function.

function calls

Posted: Mon Jan 17, 2005 3:12 pm
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

Posted: Mon Jan 17, 2005 3:25 pm
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.

function calls

Posted: Mon Jan 17, 2005 4:30 pm
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