send an e-mail on the form to send only when a field has been modified

advertisements

I have a form to edit a job, a job has a status column which can be 1, 2 or 3

<?php echo $this->Form->input('status', array('label' => '', 'options' => $status)); ?>

When i submit the form i want to check if the value of status is equal to 3, if it is then i want to send an email. BUT i dont want to send the email if the value was 3 already.

Is there an easy way in cakephp to check the previous value to the new value etc?

Thanks.


No need to mess with sessions, or indeed set the value beforehand.

Basically when you edit the record, you get the current records status value from the table. If it's already 3, we do not want to send an email, so set a boolean.

Update the record as required.

If the status was not 3, and the new status is, send the email.

I haven't filled in the whole method; but you should get the idea:

$send_email = true;
$current_status = $this->Job->field('status');
if($current_status==3) {
    $send_email = false;
}

// save the record

if($send_email==true && $this->data['Job']['status']==3) {
   //send the email
}