1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Conditional email - date plugin

Discussion in 'Community' started by jo-ka, Jul 6, 2019.

  1. jo-ka

    jo-ka Member

    Level: Community
    Hello.

    I' have a conditional email form plugin, which sends an email everytime one of the form fields is updated with new values. Something like this and is working for all elements except date element.

    So, this works:

    upload_2019-7-6_1-10-59.png

    But if the element is a date element, the email is sent everytime, even though the value is not changed. The mail body then has no value for the date, but the email is sent anyway.

    So, for the date plugin, I have this condition:

    upload_2019-7-6_1-13-54.png

    I've tried with and without _raw for both fields but with no avail.

    Also, the value on the database does'nt change at all, as the time value is allways set like 00:00:00.

    The element is set for Local Time as the site is only used locally.

    upload_2019-7-6_1-17-18.png

    What can possibly be wrong?
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    Check with var_dump(...);exit; what you really get.
    I think for the date element (and also dbjoins etc) $origData is an array.
     
  3. jo-ka

    jo-ka Member

    Level: Community
    Yes, it's an array in deed.
    So how shall I use it here?

    Tried like this, but the result is the same:

    PHP:
    $origData[0]["fab_juizes___data_exame_medico"];
    If I use it like this, nothing happens:

    PHP:
    $origData[0]->["fab_juizes___data_exame_medico"];
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    $origData[...][0]
    But for comparing it must be exactly the same date/time format so maybe you have to do additionally some string handling.

    Gesendet von meinem SM-G930F mit Tapatalk
     
  5. jo-ka

    jo-ka Member

    Level: Community
    So, I've made this change:
    PHP:
    return '{fab_juizes___data_exame_medico}' != $origData["fab_juizes___data_exame_medico"][0];
    but sitll no luck.

    Where can I put the
    PHP:
    var_dump(...);exit;
    code, so I can check what's beeing compared?
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Community
    Before the return do
    var_dump('{fab_juizes___data_exame_medico}',$origData["fab_juizes___data_exame_medico"][0]);exit;
     
  7. jo-ka

    jo-ka Member

    Level: Community
    I just get this...

    Code (Text):
    string(0) "" string(1) "0"
     
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Hmm, I can't replicate this. Also odd that your main form placeholder is empty as well.

    Can you just do ...

    var_dump($origData);exit;

    ... and lets see the whole array.

    -- hugh
     
  9. jo-ka

    jo-ka Member

    Level: Community
    OK, I've ended up doing this:
    PHP:
    //first validade if the form element is empty or null
    $aux='{fab_juizes___data_exame_medico_raw}' == "" ? "0000-00-00 00:00:00" : '{fab_juizes___data_exame_medico_raw}';

    //then, send the email only if the new value and original value are different
    return $aux != $origData["fab_juizes___data_exame_medico"];
    Working as wished.
     

Share This Page