We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

HOW: Photo description make Required? | Forum

David
David Oct 8 '14

Like selecting Album is required when photo is uploading...

How to make PHOTO upload DESCRIPTION required?

In what file we can make it?



Guna
Guna Oct 10 '14
I believe you use Photo Plugin. I am giving the answer as I assume you use Photo plugin.


go to ow_plugins/photo/classes/ajax_upload_form.php


you can find the below code there.


$desc = new Textarea('description');


After this code, include the below code.


$desc->setRequired();


this code will make the field required. Test it and tell us whether this is worked or not?

David
David Oct 12 '14

No! Your hack does NOT working!

After this I can't upload any photo because of message: "Please fill the form properly".

Have any good idea?

Guna
Guna Oct 16 '14
You wanted the photo description is required right?


$desc->setRequired(); is the correct syntax to make a field required.


I am surprised it didn't work well for you

The Forum post is edited by Guna Oct 16 '14
David
David Oct 16 '14

Yes I did.


Unfortunately if you have Oxwall 1.7.1 installed, this - $desc->setRequired(); - is NOT enough and such message: "Please fill the form properly" will be showing after insertion of $desc->setRequired(); in ow_plugins/photo/classes/ajax_upload_form.php


Have any good idea?

Guna
Guna Oct 17 '14
To make a field as required, it is the solution. Do you want all photo's description is required? or Album's description is required?
David
David Oct 17 '14

I wrote exactly: PHOTO DESCRIPTION.

I want to make this field is mandatory when user uploading any photos!

Please try your solution and make sure that it does not work...

Daisy Team
Daisy Oct 20 '14
David, Guna's solution is correct. This is the standard validator which throws out the Please fill the form properly error message. If you need your custom message, please try using this method:

$validator = new RequiredValidator();
        $validator->setErrorMessage(OW::getLanguage()->text('photo', 'custom_msg'));
        $desc->addValidator($validator);


custom_msg
- you should create a key with the custom message via Admin Area.
David
David Oct 20 '14

Quote from Daisy $validator = new RequiredValidator();

Dear Daisy. I don't need any of error messages at all, IF USER FILLED the PHOTO DESCRIPTION.

Can you please understand it...

But if I wrote this line: $desc->setRequired(); - in the code, this message "Please fill the form properly" throws out even when User filled the photo description.

Do you understand what I mean?

The Forum post is edited by David Oct 20 '14
David
David Oct 20 '14
Just look at the screen... and thus User can't upload any pics:



Guna
Guna Oct 20 '14
Thanks Daisy for the note you have given. We understood David. I will test in my localhost to upload a photo album and get back to you soon.
David
David Oct 20 '14
NOT just to upload a photo album BUT upload a photo! :)
Daisy Team
Daisy Oct 21 '14
David, sorry for misleading, the solution we gave you was for the album description. If you need to make the photo description field required follow these steps:

1. Go to /ow_plugins/photo/static/js/upload.js file
2. Find the following string:

owForms['ajax-upload'].addElement(new OwFormElement(rotateId, rotateId));

3. Replaces this code:

owForms['ajax-upload'].addElement(new OwFormElement(rotateId, rotateId));
owForms['ajax-upload'].addElement(new OwFormElement(descId, descId));

with this one:
  owForms['ajax-upload'].addElement(new OwFormElement(rotateId, rotateId));
            var element = new OwFormElement(descId, descId);
            element.addValidator({
                validate : function( value ){
value = _elements.descEditors[slotId].getValue().trim();
                    if(  $.isArray(value) ){ if(value.length == 0  ) throw "text"; return;}
                    else if( !value || $.trim(value).length == 0 || value === OW.getLanguageText('photo', 'describe_photo') ){ throw "text"; }
                },
                getErrorMessage : function(){ return "text" }
            });
            owForms['ajax-upload'].addElement(element);

4. Go to /ow_includes/config.php enable the DEV_MODE, refresh the page and disable the DEV_MODE.

5. Go to /ow_plugins/photo/classes/ajax_upload_form.php file add the following string:

$this->setEmptyElementsErrorMessage('');

after this one:

$this->setAction(OW::getRouter()->urlForRoute('photo.ajax_upload_submit'));

6. Clear the browser cache and upload the photo.
The Forum post is edited by Daisy Nov 4 '14
David
David Oct 21 '14

Thanks, but your solution is not enough.


Because if user select a photo for uploading, then click on Submit, script shows a message that selecting an Album is required, then user selects an Album and then click on Submit, and NO NEED to fill a photo description at all - script uploaded this photo without a description!


I mean that most of users do this action and your solution will not make them required for photo description.


Can you please write better, more accurate solution for this problem?

Daisy Team
Daisy Oct 21 '14
This is as accurate solution as possible which works correctly.  The .js file you've changed was cached in the browser, that's why you are still able to upload the photo without adding the description. You should clear the browser cache. Also, make sure that you recompiled the static code by enabling the DEV_MODE - simply open the /ow_static/plugins/photo/js/upload.js to see if the changes exist in this file.
David
David Oct 22 '14

I've tried your method more and more, and as you wrote and such and otherwise...


Your hack DOES NOT work properly, because, as I wrote above, you first select an Album then select a photo then you click Submit - and you get an Error.

Then you fill a description and voila!


But I propose you, as I wrote above, first select a photo, then click Submit - you get an Error, then simply select an Album but NOT filling a description, and voila! - your photo submitted without a description.


Please, I repeat once again, try this way and you will see that your fix is not enough!


Please help me to get a real solution :)



Daisy Team
Daisy Oct 24 '14
David, if you make changes in the code -  it's supposed that you have strong programing skills. I want to point your attention to that fact that we do not provide the direct instructions on how to make this or that modification on the standard basis,  but provide the examples of the code and files which you should change.  I've gave you the code and file and you should make changes on your own.

Anyway, because this solution will may be useful for other developers, to make the modification work by the exact way you need - please use the following code instead of the code provided in my instructions in the third step:

 owForms['ajax-upload'].addElement(new OwFormElement(rotateId, rotateId));
            var element = new OwFormElement(descId, descId);
            element.addValidator({
                validate : function( value ){
value = _elements.descEditors[slotId].getValue().trim();
                    if(  $.isArray(value) ){ if(value.length == 0  ) throw "text"; return;}
                    else if( !value || $.trim(value).length == 0 || value === OW.getLanguageText('photo', 'describe_photo') ){ throw "text"; }
                },
                getErrorMessage : function(){ return "text" }
            });
            owForms['ajax-upload'].addElement(element);

P.S. I would really appreciate if you'd described problems as detailed as possible, so we could have solved them asap, but not wasted the time for investigation.
David
David Oct 27 '14

I'm really sorry but your last code modification doesn't work at all.

I'm sure that you even don't test it on your side.

And even Guna stopped to answer because he does not have right solution.

What a pity, I did not wait for fix...

P.S. I have programing skills and no need to talk about it...

Daisy Team
Daisy Oct 28 '14
David, did you make changes in the code I've provided to make it work the way you need? If so, what kind of changes did you make? Could you share them?

If not, could you please describe in more details what exactly does not work in the provided solution? Before I gave you the solution I've carefully tested it and it still works on my site. So, seems you still cannot provide the accurate explanation about the technical effect you are trying to achieve, thus, I cannot provide you with the accurate  solution.

Please be more specific.
Guna
Guna Oct 28 '14
I don't have an option for like button here. If it presents, I would give thousands of likes for Daisy's effort. @David Are you working in Photos plugin ? or any other plugin?
Pages: 1 2 »