Keyword

[SOLVED] image upload and extra fields required

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 7 months ago #119273 by Josh
Thanks very much Krikor - I will take a look this evening as I need to leave the office shortly. Will let you know what I figure out, thanks again!

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

  • Josh
  • Josh's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 7 months ago #119274 by Josh
Ok so I tried something like this but this is really not my forte

<?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::_('select and image', true)."' );
return false;
}

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

?>

Still no go tho..
Any assistance or reference 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 6 months ago - 10 years 6 months ago #119275 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
var files = \$K2('.fileUpload').val(); 

       if(files=='')
       { 
          alert('No image selected');
          return false; 
       } else {
      // Do stuff
}

Did you try something like this?

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 6 months ago - 10 years 6 months ago #119276 by Josh
Hi Krikor

My apologies for the delay - been a bit swamped so this had to take the backburner for a few days.

Thanks a stack for the code above - I tried it however it still allows me to save and doesnt prompt me to add an image before being allowed to save.

I tried this..


/**
* @version $Id: itemform.php 1279 2011-10-27 16:52:58Z joomlaworks $
* @package K2
* @author JoomlaWorks www.joomlaworks.gr
* @copyright Copyright (c) 2006 - 2011 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: www.gnu.org/copyleft/gpl.html
*/

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

$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)."' );
}

var files = \$K2('.fileUpload').val();

if(files=='')
{
alert('No image selected');
return false;
}

else {
syncExtraFieldsEditor();
\$K2('#selectedTags option').attr('selected', 'selected');
submitform( pressbutton );
}
}
");


Thanks a stack mate - scripting isnt really my strongpoint :)

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 6 months ago #119277 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: image upload and extra fields required
$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('.fileUpload').val() == '')
		{
			alert('No image selected');
			return false;
		}

		else {
			syncExtraFieldsEditor();
			\$K2('#selectedTags option').attr('selected', 'selected');
			submitform( pressbutton );
		}

	}


");

This forces the user to upload a new item each time. tested it and works.
$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('.fileUpload').val() == '' &&  \$K2('#existingImageValue').val() == '' )
		{
			alert('No image selected');
			return false;
		}

		else {
			syncExtraFieldsEditor();
			\$K2('#selectedTags option').attr('selected', 'selected');
			submitform( pressbutton );
		}

	}
");

This will check both the new AND existing image fields.

Please note this ONLY for adding new item, You should make a case where the default code is used when the $task is editing.

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 6 months ago #119278 by Josh
HI Krikor

Thanks for that mate! I tried it as below but I must be missing something - tell me, this is for adding new article via the frontend right?

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

More
10 years 2 months ago #119279 by Jared
Replied by Jared on topic Re: image upload and extra fields required
Hello,

I am trying to do this too and it doesn't seem to work. I am not sure why it doesn't validate. Is there an update on this?

Thanks!

Jared

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

More
10 years 2 months ago #119280 by Jared
Replied by Jared on topic Re: image upload and extra fields required
Thank you. This actually works. In my case the submit item menu item I was using was using the wrong sub template. Noob error.

Thanks for your help on this Krikor!

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

More
10 years 2 months ago #119281 by Jared
Replied by Jared on topic Re: image upload and extra fields required
Hi Again,

Thank you for this code. Implemented it and it works fine. However, I just realized that it requires the user to upload an image again when they are editing the post. Can you please point me in a direction to resolve this? I see that you say we should create a case when $task is being used. Would you be able to elaborate on that more? Your assistance is greatly appreciated.

Thank You!

Jared

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


Powered by Kunena Forum