postbil.com Posted March 26, 2010 Share Posted March 26, 2010 Hello Phofreaks Now I have a new problem. I had created a date validation function after the script has been validated by the day, I will create a timestamp. If I print the time stamp to the screen directly from the function it works fine, but if I print it from my html form, I get nothing. how can it be? And in my role, I have some error messages, but if I make a mistake, do not I get an error. Is there someone who can explain to me what is going wrong?? Thank postbil.com Here is my function [function.php] <?php function validateDate($date, $tsDate, $errors){ if(!preg_match('|^\d{2}-\d{2}-\d{4}$|', $date)){ $errors[] = urlencode('error date. dd-mm-yyy'); }else{ list($day, $month, $year) = explode('-', $date); if(!checkdate($month, $day, $year)){ $errors[] = urlencode('error date. dd-mm-yyy'); }else{ $tsDate = mktime(0, 0, 0, $month, $day, $year); echo $errors; echo $tsDate; } } } ?> And here is my html form [send.php] <?php include ('function.php'); ?> <html> <head> </head> <body> <form action="send.php" method="post"> <input type="text" name="date" > <input type="submit" name="submit" value="send"> <?php if(isset($_POST['submit']) && $_POST['submit'] == 'send' ){ global $tsDate; $date = isset($_POST['date']) ? trim($_POST['date']) : ''; validateDate($date, $errors, $tsDate); echo $tsDate; echo $errors; } ?> Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 26, 2010 Share Posted March 26, 2010 Not that it matters cause you only use $date but the order does not match between the function call and the function itself. You need return something from the function return $tsDate; Then you need to ask for something when you call the function $tsdate=validateDate($date); echo $tsdate; If you desire to return both the data and errors you will need to put them into an array then return the array HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted March 27, 2010 Share Posted March 27, 2010 validateDate($date, $errors, $tsDate); echo $tsDate; echo $errors; This is your problem. The arguments passed to the function are not modified by the function. What you would need to do is return values from your function. Here is what you want: function validateDate($date){ if(!preg_match('|^\d{2}-\d{2}-\d{4}$|', $date)){ $errors[] = urlencode('error date. dd-mm-yyy'); }else{ list($day, $month, $year) = explode('-', $date); if(!checkdate($month, $day, $year)){ $errors[] = urlencode('error date. dd-mm-yyy'); }else{ $tsDate = mktime(0, 0, 0, $month, $day, $year); } $tmpArray=array($tsDate, $errors); return $tmpArray; } } if(isset($_POST['submit']) && $_POST['submit'] == 'send' ){ global $tsDate; $date = isset($_POST['date']) ? trim($_POST['date']) : ''; $dateAndError=validateDate($date); $tsDate=$dateAndError[0]; $errors=$dateAndError[1]; echo $tsDate; echo $errors; } Quote Link to comment Share on other sites More sharing options...
postbil.com Posted March 27, 2010 Author Share Posted March 27, 2010 thanks a lot.. it works Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.