Keyword

[SOLVED] image upload and extra fields required

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 11 months ago #119263 by Josh
Hi

I am running a site with a few sub templates and was wondering if there is any way we are able to make to image upload feature required? AIso is this possible for extra fields too? Or even selected extra fields?

I have an events category and would like to force users to upload an image for their submissions(via frontend) and also to fill in the extra fields by default. Is this possible?

Many thanks!

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 11 months ago #119264 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
Hello Josh,

For the extrafields it's quite simple. They have a check for being required or not. You can choose which are and which not.

For front end editing you should override the k2 JS scripts and itemform.php to add the functionality you want. Maybe a simple JS script that disables the submit will do the trick.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 11 months ago #119265 by Josh
Hi Krikor

Thanks for the reply - now that you mention it I have actually seen the extra fields required button, just had a blind moment.. Thanks for the JS suggestion - will check it out and revert should I find a solution. :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 11 months ago #119266 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
Just make sure you override the files and not edit the core ones, and you won't have any issue.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 11 months ago #119267 by Josh
Hi again

Thanks for that - ok for the image required function I am having problems..

In itemform.php i found

defined('_JEXEC') or die;

$document = JFactory::getDocument();
$document->addScriptDeclaration("
Joomla.submitbutton = function(pressbutton){
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}
if (\$K2.trim(\$K2('#title').val()) == '') {
alert( '".JText::_('K2_ITEM_MUST_HAVE_A_TITLE', true)."' );
}
else if (\$K2.trim(\$K2('#catid').val()) == '0') {
alert( '".JText::_('K2_PLEASE_SELECT_A_CATEGORY', true)."' );
}



else {
syncExtraFieldsEditor();
var validation = validateExtraFields();
if(validation === true) {
\$K2('#selectedTags option').attr('selected', 'selected');
submitform( pressbutton );
}
}
}
");


I thought this might help however when I try to find the image reference in the database there isnt any due to the way k2 handles images.

How would I be able to implement a check to see if the input has a value selected and only if it does to allow the submit button to work?

something like..

if ($_FILES === 0)

Sorry for asking but JS is not my forte so any assistance / help would be greatly appreciated

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 11 months ago #119268 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
the
\$K2.trim(\$K2('#catid').val()) == '0')
checks to see if the input is empty

you need to duplicate this piece of code and change the #catid to the input id or class you want. the .fileUpload is the upload class and the #existingImageValue is the id of the existing image input

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 11 months ago - 10 years 11 months ago #119269 by Josh
Hi Krikor

Thanks for the reply again - apologies for the late reply.
Ok yes I though something like that, ok so Ive ammended it to be

<?php
/**
* @version $Id: itemform.php 1959 2013-04-07 19:06:19Z joomlaworks $
* @package K2
* @author JoomlaWorks www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: www.gnu.org/copyleft/gpl.html
*/

// no direct access
defined('_JEXEC') or die;

$document = JFactory::getDocument();
$document->addScriptDeclaration("
Joomla.submitbutton = function(pressbutton){
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}
if (\$K2.trim(\$K2('#title').val()) == '') {
alert( '".JText::_('K2_ITEM_MUST_HAVE_A_TITLE', true)."' );
}
else if (\$K2.trim(\$K2('#catid').val()) == '0') {
alert( '".JText::_('K2_PLEASE_SELECT_A_CATEGORY', true)."' );
}

else if (\$K2.trim(\$K2('#.fileUpload').val()) == '0') {
alert( '".JText::_('K2_PLEASE_SELECT_AN_IMAGE', true)."' );
}

else {
syncExtraFieldsEditor();
var validation = validateExtraFields();
if(validation === true) {
\$K2('#selectedTags option').attr('selected', 'selected');
submitform( pressbutton );
}
}
}
");

?>

The problem is that when I hit save that the form kicks the errors correctly for the title and category fields but seems to not be checking/validating the image upload input. Do you know if there is another place I need to invoke the check/validation? Also I am wondering if it should validate that an image has been already uploaded but rather that it should check that an image has been selected on save and if yes then continue checks and allow save.

Thanks again for any assistance. I think this could be a nice feature others might be interested in too.
Cheers
Josh

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 11 months ago #119270 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
You have to use .fileUpload instead of #.fileUpload .
You can combine the checks for the input using an && element.

Let me know if that did the trick :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 11 months ago #119271 by Josh
Thanks Krikor!

Ok no luck so far - I changed to .fileUpload but still it allows me to save and no error when no image is added. I am not sure exactly what sort of validation I should be researching.

Thanks again I really appreciate it!

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 11 months ago #119272 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
No problem Josh :)
Always glad to help.

There is a related post on Stack Overflow that will help you out:

stackoverflow.com/questions/14814075/jquery-validate-file-inputs

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum