[SOLVED] Check default value of custom field

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
10 years 8 months ago #185249

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.4.29

Hi

I have a custom text field that is 'required' where the user has to enter a person's name. I have set the default value to 'Enter name'. How can I ensure that the form is saved with something other than the default value?

Thanks
Trevor

Last edit: 10 years 8 months ago by trevsmiff.

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

  • Posts: 12953
  • Thank you received: 1778
10 years 8 months ago #185267

Hello Trevor,
There no option to do that, so without moving the 'Enter name' text or directly edit the Hikashop code.

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

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
10 years 8 months ago #185390

Hi Mohamed

I wanted to leave the without a default but then I can't save it, I get:
'Error
Please complete the Members name: field'

Out of interest I tried opening the Firstname field and saving it without changing anything and get a similar error. Looks like the custom fields must be saved with a default value if they are 'required'.

Trevor

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

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
10 years 8 months ago #185435

I have managed to get it working but it was a bit messy!

In the Field Editor I cleared out the 'Default Value' and set 'Required' to 'No' and saved the changes.
I then opened up the database and set 'field_required' value to 1 in the 'hikashop_field' table.

The field is now presented as an empty field but raises a warning if the user tries to add the item to the cart without entering a value.

Best regards
Trevor

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

  • Posts: 13201
  • Thank you received: 2322
10 years 8 months ago #185436

Hi,

That's a way of doing that, else you can edit the file "administrator/components/com_hikashop/classes/field.php" and replace:

	function check(&$field,&$value,$oldvalue) {
		if(is_string($value))
			$value = trim($value);

		if(($field->field_namekey == 'field_default' && $app->isAdmin()) || !$field->field_required || is_array($value) || strlen($value) || strlen($oldvalue))
			return true;

		if($this->report) {
			$app = JFactory::getApplication();
			$app->enqueueMessage(JText::sprintf('PLEASE_FILL_THE_FIELD',$this->trans($field->field_realname)),'error');
		}
		return false;
	}
By:
	function check(&$field,&$value,$oldvalue) {
		if(is_string($value))
			$value = trim($value);

		$app = JFactory::getApplication();
		if(($field->field_namekey == 'field_default' && $app->isAdmin()) || !$field->field_required || is_array($value) || strlen($value) || strlen($oldvalue))
			return true;

		if($this->report) {
			$app->enqueueMessage(JText::sprintf('PLEASE_FILL_THE_FIELD',$this->trans($field->field_realname)),'error');
		}
		return false;
	}

We will correct that issue.

The following user(s) said Thank You: trevsmiff

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

Time to create page: 0.064 seconds
Powered by Kunena Forum