i did a customization for a popup message in p4a.
here is the screenshot:
here is the code:
set red border around fields:
function setAsRequiredField( $fieldName ){
$fieldName->setStyleProperty('border-color', 'red');
$fieldName->setStyleProperty('border-style', 'dashed');
$fieldName->label->setStyleProperty('font-weight', 'bold');
}
remove formating:
function clearErrorFormatting(){
while ($f = $this->fields->nextItem()) {
$f->unsetStyleProperty('border-color', 'red');
$f->unsetStyleProperty('border-style', 'dashed');
$f->label->unsetStyleProperty('font-weight', 'bold');
}
}
sample validating function that passes a message for each field:
function validateScreen(){
$this->clearErrorFormatting();
$statusMsg = "";
$email_validator = new Zend_Validate_EmailAddress();
$notEmpty_validator = new Zend_Validate_NotEmpty();
$date_validator = new Zend_Validate_Date();
$regex_validator = new Zend_Validate_Regex('/\d{3}\-\d{3}\-\d{4}/');
if( $this->fields->title_id->getNewValue() == 0 ){
$this->setAsRequiredField( $this->fields->title_id );
$statusMsg .= "Title is required
";
}
if( !$notEmpty_validator->isValid( $this->fields->first_name->getNewValue() ) ){
$this->setAsRequiredField( $this->fields->first_name );
$statusMsg .= "First Name is required
";
}
if( empty( $statusMsg ) ){
$this->insertMember2();
} else {
$this->warning($statusMsg);
}
}
the message for each error is concatenated to this variable, $statusMsg, than passed to the warning function for p4a. once it is passed to the function, it show the popup for the error messge.
1 comment:
wtf is p4a? oh dam these frameworks popup every day. I need to build one and see how many people wuld find it useful.
Post a Comment