Hi Guys,
I have a form that submits and updates a data object but prior to the actual update I want to check whether a link actually exists on a page. If the link exists then the update can progress otherwise if the link doesn't exist then it should redirect the user back to the original form and give them a notice.
But what is happening is that I am getting a warning
[User Warning] Already directed to /placements/complete/3; now trying to direct to /placements
So the code is failing the initial "if($this->checkforlink() == false){" check and doing the redirect, but then continuing on the execution of the rest of the updatecompletion() which is not what I want. I want to check for the link, if it fails, end execution and then redirect to the new page.
If I try to exit() after Director::redirect('/placements/complete/'.$data['AdvertisementID']); then all I get is a white screen.
I might be missing something extremely obvious here, but would love any help you might have.
public function checkforlink() {
// test to simulate a failed check for the link
return false;
}
public function updatecompletion($data, $form) {
if($this->checkforlink() == false){
Session::set('notice', true);
Session::set('noticeType', 'bad');
Session::set('noticeText', 'Opps - It doesn\'t look like that link is actually showing up in the location you have provided yet. Please check that it exists before setting the placement as completed.');
Director::redirect('/placements/complete/'.$data['AdvertisementID']);
}
// UPDATE Code goes in here
if($Advertisement->write()){
Session::set('notice', true);
Session::set('noticeType', 'good');
Session::set('noticeText', 'Okay, thanks for letting us know that this placement is completed.');
Director::redirect('/placements');
}else{
Session::set('notice', true);
Session::set('noticeType', 'bad');
Session::set('noticeText', 'Opps - It doesn\'t look like that placement was for you. Nice try though ;)');
Director::redirect('/placements');
}
}