Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Showing the user a friendly validation error in OnBeforeWrite

$
0
0

Hi Everyone

I want to show my user a friendly error...

public function onBeforeWrite() {

//check a branch doesnt already exist for this Member, as they are only allowed one branch per login
if(!$this->ID) {
if(CompanyBranch::get()->where("MemberID='".$this->MemberID."'")) {
user_error('Only one branch is allowed per franchisee', E_USER_ERROR);
exit();
}
}

//get the lat long details if not present
if(!$this->MapLat||!$this->MapLong){
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($this->getFullAddressMAPAPI()).",GB&sensor=true";
$geocode = json_decode(file_get_contents($url));
$geo = $geocode->results[0]->geometry->location;
$this->MapLat = $geo->lat;
$this->MapLong = $geo->lng;
}
parent::onBeforeWrite();

}

However this just throws the black box in the top right with a php error, rather than a nice warning to the user that they can do what they are trying to do.

Any ideas on how to show a friendly error and stop the process in this instance?

Thanks


Posted to: Showing the user a friendly validation error in OnBeforeWrite | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles