Validating a photo upload

Status
Not open for further replies.

redant

Member
Hi

Please can someone cast an eye over my code below and tell me why its not working.

What I'm trying to achieve:
If user has uploaded a photo - do nothing.
If user has not uploaded a photo - insert a generic photo based on which radio button has been selected.

Using php plugin on form with OnBeforeProcess:

//Check if animal type is dog
If ({animals___type}=='Dog')
//Check that a photo has not been uploaded
{If (empty({animals___upload_photo})
//Then apply a generic photo
{$formModel->updateFormData('animals___upload_photo','Doggy.jpg', true);}
}
 
Firstly, thanks for the prompt reply, Troester. Appreciate it.

Thanks, I hadn't spotted that. I fixed the quotes to:
//Check if animal type is dog
If ('{animals___type}'=='Dog')
//Check that a photo has not been uploaded
{If (empty('{animals___upload_photo}')
//Then apply a generic photo
{$formModel->updateFormData('animals___upload_photo','Doggy.jpg', true);}
}

Still not working though. No data is written to the database on submission.

To test I simplified it further to test and used:
If (empty('{animals___upload_photo}')
{$formModel->updateFormData('animals___upload_photo','Doggy.jpg', true);}

Have also tried: If (empty('{animals___upload_photo_raw}') with the same result ( nothing submitted.)

The form also has a redirect applied. I have noticed that when I submit with my code the redirect also does not fire and the page returned is the home page. If I remove my script the page redirects to the correct page so clearly its a syntax thing. For the life of me I just cannot see it though ...
 
You are missing a close paren on the if empty ...

Code:
if ('{animals___type}' == 'Dog')
{
    //Check that a photo has not been uploaded
    if (empty('{animals___upload_photo}'))
    {
         //Then apply a generic photo
        $formModel->updateFormData('animals___upload_photo','Doggy.jpg', true);
    }
}

-- hugh
 
Thanks, Hugh. Must've had tired eyes last night. Missed that one too!

However, even with fixing the closing parenthesis I still have the same behaviour.

Even with the simplified version of the script (below), I still get the same behaviour:

If (empty('{animals___upload_photo}'))
{$formModel->updateFormData('animals___upload_photo','Doggy.jpg', true);}

I found this post:
http://fabrikar.com/forums/index.ph...on-depending-of-values-of-other-fields.44734/
in which someone was attempting to do a similar thing and have tried with guidance from there but also run into the same problem where the data simply is not stored.
 
Ok - worked this out. For some reason the empty parameter is causing the issue.

When I do:
If ('{animals___upload_photo}'=='')
{$formModel->updateFormData('animals___upload_photo','Doggy.jpg', true);}

It works.

On PHP 5.4.45, Joomla 3.5.2, Fabrik 3.5.1

Does anyone else see the same behaviour? It would be nice to know why it fails using "empty".

Nevertheless - Thanks again for the help. Always appreciated. Danke.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top