CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Validation Rule Problem with PHP

Print topic Send  topic

Author Message
Rick

Posts: 52
Posted: 01/12/2004, 7:56 AM

Using CCS 2.0.5.6, PHP, MySQL, Windows XP Prof for development

I want to validate that the date (selected with the date picker control) is greater than or equal to todays date and less than 30 days in the future.

I got this to work in a couple of minutes using ASP and Access but am struggling to get it to work in PHP and MySQL.

------------------------------------
The following Validation Works Great Using ASP and Access db Date when set in the 'Data' tab of the Text Box Properties of the Date:

Validation Rule for the Date: rpt_date_created.Value >= Date() and rpt_date_created.Value < (Date() + 30)

ASP Validation Text: Date Cannot be boefor todays date or more than 30 days into the future.

-------------------------------------
What do I need to do to get this to work with PHP and MySQL?
To start I tried a single condition in PHP / MySQL.

Validation Rule: rpt_date->GetValue() >= mktime(0, 0, 0, date("m"), date("d"), date("Y"))

Validation Text: Report Date Must be todays date or later

Browser Error just bringing up the page is:
'Parse error: parse error, unexpected T_OBJECT_OPERATOR in c:\inetpub\wwwroot\testa\tst.php on line 95'
Nothing else is displayed in browser.
---------------------------------------
Since I could not get the date validation to work I tried a validation rule with a text field.
This also did not work with text field in PHP with MySQL db:

Validation Rule: rpt_name->GetValue() = "Expense Rpt"

Validation Text: Report Name must be Expense Rpt

Browser Error just bringing up the page is:
'Parse error: parse error, unexpected T_OBJECT_OPERATOR in c:\inetpub\wwwroot\testa\tst.php on line 89'
Nothing else is displayed in browser.
-------------------------------------------
It seems like it does not like the -GetValue() but the Help file 'GetValue Method' shows <control>->GetValue(value) so I thought I was doing it properly.

If only the Validation Rule Property help showed a PHP example (it shows only as ASP example). My biggest wish for CCS is for the help file to show an example for PHP and ASP for every method and property.

Any help would be greatly appreciated.

Rick
View profile  Send private message
jstuart


Posts: 26
Posted: 01/13/2004, 8:15 AM

Rick, it's got to be: $name_of_form->rpt_name->GetValue(). Note: you MAY MAY be able to use $this->GetValue().
_________________
Jeff Stuart
jstuart@computer-city.net
View profile  Send private message
Rick

Posts: 52
Posted: 01/13/2004, 10:02 AM

Jeff,

Thank you for your reply.

Could not get form name to work but YOU WERE CORRECT with the idea of $this->GetValue. I can now get the Validation Rule to work with the following on a text field:

For Example:
$this->rpt_name->getvalue() == "Expense Rpt" which will return an error message if the text field rpt_name is not equal to "Expense Rpt".

(I do condider this to be undocumented which is unfortunate as it wastes a lot of time. You really have to go into the generated validation code and guess what needs to be done.)

Using this same approach I am trying to get a date validation with the following but so far any and all entered dates either before or after the current date result in the validation message, ie. no entered dates pass validation.

Ex. Validation Rule:
$this->rpt_date->getvalue() < mktime(0, 0, 0, date("m") , date("d"), date("Y"))
Validation Text:
Report Date must be less than today.

Also, tried replacing above Validation Rule with:
$this->rpt_date->getvalue() > date("n/d/y")
but got the same results. I tried this because this compares the field date that has the exact same format as date("n/d/y") produces.
Ie. Entered date of 1/2/04 is comparted to system formated date of 1/2/04 if system date is Jan 3, 2004.

If I change the less than sign to a greater than sign '>' just the opposite happens, all entered dates pass validation. I then cannot get it to display the Validation text no matter what date I put in.

I also tried the following in the form On Validate event but cannot get it to work with a date (Got it to work with a text field though).

Code Tried:
$str_date = date("n/d/y"); // todays date
// Also tried below line in place of above line with same result
// $str_date = mktime(0, 0, 0, date("m") , date("d"), date("Y"));

$str_report_date = $report->rpt_date->GetValue();

if ($str_report_date < $str_date) {
$report->Errors->addError("The report date must be current date");
}

I tried putting in an echo statement to see what the report_date field displayed;
echo $str_report_date;

This did not display the value but added 'Array' to the browser screen.

I have tried a few date formats and currently have it set up as 'Short Date'.

I find working with dates in CCS and PHP a little confusing so that is probably most of my problem at this point. Although I am trying to move everything I do to PHP and MySQL I guess I have a lot more to learn.

Again thanks for previous response and also if you or someone else is able to shed any more light on this.

Rick

View profile  Send private message
EMG


Posts: 35
Posted: 01/13/2004, 10:07 AM

I'd like to clean it up for you but here is an example you can tweak:

// if sTransDate more than 5 days prior or later than header date , set sTransDate to sHeaderDate

$iSeconds = strtotime($sTransDate)-strtotime($sHeaderDate);
$iDayDiff = intval($iSeconds/86400);
if($iDayDiff < -5 || $iDayDiff > 0 ) $sTransDate = $sHeaderDate;
View profile  Send private message
Rick

Posts: 52
Posted: 01/13/2004, 12:05 PM

Thanks for the reply.

I modified my code to give your example a try.

My Code:
$iSeconds = strtotime($str_date)-strtotime($str_report_date);
$iDayDiff = intval($iSeconds/86400);
if($iDayDiff < -5 || $iDayDiff > 0 ) {
$report->Errors->addError("The report date must be current date");
}

The problem is in the first line. I have assigned $str_report_date the value of field report_date with the code:
$str_report_date = $report->rpt_date->GetValue();

That line does not give an error, but when it runs thru the validation the browser returns the following:
"Notice: Array to string conversion in c:\inetpub\wwwroot\testa\report_events.php on line 41"

The problem is in the code: strtotime($str_report_date)
because if I change $str_report_date from a form field date to a system date variable the error goes away. However, it is the field that I need to validate.

I think your code example would be great if I could get the form field value out of the array and back into a seconds format so I could compare similar time formats. I don't however know how to do that.

Any more ideas?

Rick
View profile  Send private message
EMG


Posts: 35
Posted: 01/13/2004, 12:54 PM

format you dates first as mm/dd/yy:

date("m/d/y", $str_date )
View profile  Send private message
Rick

Posts: 52
Posted: 01/13/2004, 7:16 PM

Don't think it will work with Validation Rule but finally got it to work with form Validation event. Last thing I did not understand was instead of parenthesis (0) you use brackets to express array value [0].

Code that worked:
$str_report_date = $report->report_date->GetValue();

if ($str_report_date[0] < strtotime($str_date)) {
$report->Errors->addError("The report date must be a current date");
}

echo strtotime($str_date)." ";
echo $str_report_date[0]; // to display array value

Thank you Jeff and EMG for helping me through this. I learned a few things in the process.

Rick
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.