Hi,
I just have the exact requirement which you have described. I did every thing as you specified. But i am not able to get the previous data and even the error message. I have the module with the name mango_Patients. In this i would like to check the email and some other fields.
The logichook code is:
PHP Code:
class ValidateEmail{
function validate(&$bean, $event, $arguments){
if($this->emailValidate($bean->doctoremergemail)){
$_SESSION['myError']="Emergency Email is invalid";
//build the URL to return to
$module=$_REQUEST['module'];
$action="&action=EditView"; //we need to have EditView b/c that is the action we are taking
$returnModule="&return_module=".$_REQUEST['return_module'];
$offset=$_REQUEST['offset'];
if($offset=="") {
} else {
$offset="&offset=$offset";
}
$stamp=$_REQUEST['stamp'];
if($stamp=="") {
} else {
$stamp="&stamp=$stamp";
}
if($recordId=="") {
$returnAction="&return_action=DetailView";
} else {
$recordId="&record=".$recordId;
}
$url="index.php?module=".$module.$offset.$stamp.$action.$returnModule.$returnAction.$recordId;
header("Location: $url");
$_SESSION['MyBean']=$bean; //store the bean in session so we can retrieve the values later
exit;
}
if($this->emailValidate($bean->doctorprimaryemailaddress)){
//echo "Primary Email worng";
}
}
function emailValidate($email){
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return 1;
}
}
}
Below is the code i have implemented in custom/modules/mango_Patients/views/view.edit.php (I dont have the view directory i created and proceded)
PHP Code:
<?php
require_once('include/MVC/View/views/view.edit.php');
class mango_PatientsViewEdit extends ViewEdit {
public function preDisplay() {
//this displays errors among other things
$this->errors[]=$_SESSION['myError'];
unset($_SESSION['myError']);
parent::preDisplay();
}
public function display() {
if(isset($_SESSION['MyBean'])) { //an error must have occurred bean is in session
$sessionBean=$_SESSION['MyBean'];
$fieldKeys=array_keys($_SESSION['MyBean']->field_defs);
foreach($fieldKeys as $key) { //get each field the user typed and set them into the current bean
if($sessionBean->field_defs[$key]['type']=="date") {
//dates get formated into YYYY-MM-DD and on next submit they throw an error for me
$this->bean->{$key} =
date_format(date_create($_SESSION['PromoGroupBean']->{$key}),"m/d/Y");
} else {
$this->bean->{$key} = $_SESSION['PromoGroupBean']->{$key};
}
}
unset($_SESSION['MyBean']);
}
parent::display();
}
}
?>
I called these PHP Code:
parent::preDisplay() and parent::display()
methods from modules/mango_Patients/mango_Patients.php file.
PHP Code:
require_once('modules/mango_Patients/mango_Patients_sugar.php');
class mango_Patients extends mango_Patients_sugar {
function mango_Patients(){
parent::mango_Patients_sugar();
parent::preDisplay();
parent::display();
}
}
I am new to Sugar CRM. Please point me where i am doing wrong. I am egearly waiting for you reply.
Thanks in advance.
Bookmarks