Custom Fields - how to display one at a time

  • Posts: 69
  • Thank you received: 1
11 years 2 weeks ago #169031

-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.3
-- PHP version -- : 5.4
-- Error-message(debug-mod must be tuned on) -- : How do I...

Hi,

I have several custom fields and I would like them to display in specific areas of my page (both front end product page and back
end product form page). I do not know PHP well enough to be able to pick a specific field to display and I need your help (please).

I am working with
- administrator/templates/isis/html/com_hikashop/product/form.php
- templates/tbdp/html/com_hikashop/product/show_bock_custom_main.php

and for the form.php file I would like to know how to change this existing code to display only a single custom field of my choice.
Here is your code

<?php
// **************** BEGIN CUSTOM FIELDS  **************
if(!empty($this->fields)){?>
	<table class="admintable table" width="50%">
	<?php foreach($this->fields as $fieldName => $oneExtraField){
		if(!$oneExtraField->field_backend){
			if($oneExtraField->field_type != "customtext"){?>
		<tr><td><input type="hidden" name="data[product][<?php echo $fieldName; ?>]" value="<?php echo $this->element->$fieldName; ?>" /></td></tr>
		<?php }
		}else{ ?>
		<tr id="hikashop_product_<?php echo $fieldName; ?>">
			<td class="key">
				<?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
			</td>
			<td>
				<?php
					if(!isset($this->element->$fieldName))
						$this->element->$fieldName = $oneExtraField->field_default;
				?>
				<?php $onWhat='onchange'; if($oneExtraField->field_type=='radio') $onWhat='onclick'; ?>
				<?php echo $this->fieldsClass->display($oneExtraField,$this->element->$fieldName,'data[product]['.$fieldName.']',false,' '.$onWhat.'="hikashopToggleFields(this.value,\''.$fieldName.'\',\'product\',0);"'); ?>
			</td>
		</tr>
		<?php }
	} ?>
	</table>
<?php 
// **************** END CUSTOM FIELDS  ************** 
}?>
			

Can you help me and alter the above to show a specific field?

Thanks,

Dennis


______________
Dennis Kmetz

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

  • Posts: 84301
  • Thank you received: 13697
  • MODERATOR
11 years 2 weeks ago #169039

Hi,

It's quite easy.
After the code:
foreach($this->fields as $fieldName => $oneExtraField){

You can add :
if($fieldName!='my_field_column_name') continue;

so that it will skip the display of the fields if their column name is not my_field_column_name.

Please note though that it will only not display the HTML of the fields. The javascript checks on the fact that the field is required will still be done so the system will prevent you from validating the form if you don't display required fields.
So the easiest in that case would be to not make them required.

The following user(s) said Thank You: dkmetz@taylorbruce.com

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

Time to create page: 0.056 seconds
Powered by Kunena Forum