[Skip to main content](#vessel-content)

#   Conditional Required Fields

##

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago [\#42933](#42933) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  *[Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#42933 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")* was created by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")*

Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some do not. So instead of creating 30 different products for each participant within the organization, I've created a custom field on the order table for the name of the participant.

Now this works great, but only if every organization wants to keep track of which participant a sale is to benefit. But not all of them do. I've created a custom field, Required_Participant_Name, on the product table which is a simple yes/no radio button. Based on the value of the radio button, I would like to display the custom field on the order table for the name of the participant. Is this possible? Is there a more elegant solution to my problem? Any feedback would be greatly appreciated.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

14 years 7 months ago [\#43072](#43072) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43072 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

I understand that you want to have a conditional custom order field on the checkout based on the value of a custom product field of the products in the cart.
There is no option for that but you can do it with a few lines of code customization in the file "fields" of the view "checkout" via the menu Display-&gt;Views if you know programming. You will have to loop through the products and based on the value of that field, display or not the custom order fields.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago [\#43167](#43167) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43167 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

Thank you for your response, I've gotten the loop to execute properly and the custom fields are conditionally displayed as expected. However, if the fields are not shown and the user proceeds to the next checkout step an error is thrown asking the user to fill in the custom field even though it is not displayed. Is there a way to disable this error message as well?? If you want to see the errors I can provide you w/ URL's. Thanks again!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago [\#43276](#43276) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43276 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

In addition to displaying or not displaying the custom field on checkout, my initial thought is to manually set the custom field 'participant name' of the order table to "none" if the radio button on the product table is set to no. Then in the e-mails, edit where the custom field is printed to only display if not equal to "none". The only problem is I am not entirely sure how to reference the custom field array to set the value of 'participant name' to "none".

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

14 years 7 months ago [\#43295](#43295) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43295 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

We can look at the problem if you want. Please provide the code modifications you did and a link to the page on your website so that we can reproduce the error.

In the file "fields" of the view "checkout", you can set the default value like that:

if(empty($this-&gt;order-&gt;Required_Participant_Name)) $this-&gt;order-&gt;Required_Participant_Name='none';

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago [\#43317](#43317) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43317 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

the url you can add the product to the cart is: [ themetrocashcard.com/trenton-highschool-sample1](https://themetrocashcard.com/trenton-highschool-sample1) I will set the "required_participant" to No. Below is the code for my modified checkout / fields.php , I've left database info blank for this purpose.

&lt;?php
/**
* @package HikaShop for Joomla!
* @version 1.5.5
* @author hikashop.com
* @copyright (C) 2010-2011 HIKARI SOFTWARE. All rights reserved.
* @license GNU/GPLv3 [ www.gnu.org/licenses/gpl-3.0.html](http://www.gnu.org/licenses/gpl-3.0.html)
*/
defined('_JEXEC') or die('Restricted access');
?&gt;
&lt;?php
$cartClass = hikashop_get('class.cart');
$cart = $cartClass-&gt;loadFullCart(true);
$this-&gt;rows =&amp; $cart-&gt;products;

foreach($this-&gt;rows as $row)
{

$productClass = hikashop_get('class.product');
$product = $productClass-&gt;get($row-&gt;product_id);

if(empty($product)) continue;
if(!empty($product))
{
$hostname='';
$username='';
$password='';
$dbname='';
$usertable='jos_hikashop_product';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$query = 'SELECT * FROM ' . $usertable;
$result = mysql_query($query);
if($result)
{
while($row1 = mysql_fetch_array($result))
{
$query_result_product_id = $row1;
if($query_result_product_id == $product-&gt;product_id)
{
$required_participant_name = $row1;

}

}

}
}
}?&gt;

&lt;?php if(hikashop_level(2) &amp;&amp; !empty($this-&gt;extraFields) &amp;&amp; $required_participant_name=="TRUE"){

hikashop = Array('participant_name');
?&gt;
&lt;div id="hikashop_checkout_additional_info" class="hikashop_checkout_additional_info"&gt;
&lt;fieldset class="input"&gt;
&lt;legend&gt;&lt;?php echo JText::_('ADDITIONAL_INFORMATION');?&gt;&lt;/legend&gt;
&lt;table cellpadding="0" cellspacing="0" border="0" class="hikashop_contentpane"&gt;
&lt;?php
if(!empty($this-&gt;extraFields)){
JRequest::setVar('hikashop_check_order',1);
$this-&gt;setLayout('custom_fields');
$this-&gt;type = 'order';
echo $this-&gt;loadTemplate();
}
?&gt;
&lt;/table&gt;
&lt;/fieldset&gt;
&lt;/div&gt;
&lt;div style="clear:both"&gt;&lt;/div&gt;
&lt;?php } ?&gt;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

14 years 7 months ago [\#43414](#43414) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43414 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

Mmm, quite complex for what you want to do.

It should be like that:
Code:

$cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;loadFullCart(true); $this-&gt;rows =&amp; $cart-&gt;products; $required_participant_name = false; foreach($this-&gt;rows as $row){ $productClass = hikashop_get('class.product'); $product = $productClass-&gt;get($row-&gt;product_id); if($product-&gt;required_participant_name) $required_participant_name = true; } if(!$required_participant_name){ $doc =&amp; JFactory::getDocument(); $js="hikashop['reqFieldsComp']['order'] = Array();"; $doc-&gt;addScriptDeclaration( "&lt;!--\n".$js."\n//--&gt;\n" ); return; }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago -  14 years 7 months ago [\#43836](#43836) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#43836 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

I appreciate your help, this will now properly display or not display the custom field. However ( the custom field is set as a required field) when the field is displayed the user is now able to proceed to the next step without ever entering a value into the field. In otherwords.. right back to where we began. Here's a URL [ www.themetrocashcard.com/trenton-marketing-nyc2012](https://www.themetrocashcard.com/trenton-marketing-nyc2012) to recreate if needed, and below is the code that I currently have for checkout/fields.php

**EDIT:** In FireFox on windows, if the custom field is NOT displayed and the user proceeds to the next step an error is displayed as follows: "please fill Participant Name field" even though there is no participant name field displayed.
Code:

&lt;?php /** * @package HikaShop for Joomla! * @version 1.5.5 * @author hikashop.com * @copyright (C) 2010-2011 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); ?&gt; &lt;?php $cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;loadFullCart(true); $this-&gt;rows =&amp; $cart-&gt;products; $required_participant_name = false; foreach($this-&gt;rows as $row){ $productClass = hikashop_get('class.product'); $product = $productClass-&gt;get($row-&gt;product_id); if($product-&gt;required_participant_name == "TRUE" ) $required_participant_name = true; } if(!$required_participant_name){ $doc =&amp; JFactory::getDocument(); $js="hikashop['reqFieldsComp']['order'] = Array();"; $doc-&gt;addScriptDeclaration( "&lt;!--\n".$js."\n//--&gt;\n" ); return; } ?&gt; &lt;?php if(hikashop_level(2) &amp;&amp; !empty($this-&gt;extraFields['order']) &amp;&amp; $required_participant_name == true){ ?&gt; &lt;div id="hikashop_checkout_additional_info" class="hikashop_checkout_additional_info"&gt; &lt;fieldset class="input"&gt; &lt;legend&gt;&lt;?php echo JText::_('ADDITIONAL_INFORMATION');?&gt;&lt;/legend&gt; &lt;table cellpadding="0" cellspacing="0" border="0" class="hikashop_contentpane"&gt; &lt;?php if(!empty($this-&gt;extraFields['order'])){ JRequest::setVar('hikashop_check_order',1); $this-&gt;setLayout('custom_fields'); $this-&gt;type = 'order'; echo $this-&gt;loadTemplate(); } ?&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div style="clear:both"&gt;&lt;/div&gt; &lt;?php } ?&gt;

Last edit: 14 years 7 months ago by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

14 years 7 months ago [\#44028](#44028) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#44028 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

Ah yes. You will also have to change the file administrator/components/com_hikashop/classes/field.php so that the check, server side is skipped.
Just remove that code:

if(!$class-&gt;check($fields[$k],$val,@$oldData-&gt;$namekey)){
$ok = false;
}

Could you give a link to a product for which the field is not displayed so that we can look at your FF problem ?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago -  14 years 7 months ago [\#44105](#44105) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#44105 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

I apologize in advance if I'm becoming a burden, and truly appreciate your bearing with my inexperience in the matter. Removing that code seems to have fixed the error message when the custom field is not displayed in FireFox. But if the field is displayed you are still able to proceed to the next step without entering any value into the required custom field. I can see the following in the page source
Code:

&lt;!-- hikashop['reqFieldsComp']['order'] = Array('participant_name'); hikashop['validFieldsComp']['order'] = Array('Please enter the name of the participant that you are supporting by making this purchase: '); //--&gt;

so it is establishing that it is a required field, but the check is not functioning properly. Any thoughts? If you want to add a product to the cart to recreate the error, please visit [ themetrocashcard.com/component/hikashop/product/cid-9](https://themetrocashcard.com/component/hikashop/product/cid-9)

Last edit: 14 years 7 months ago by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

14 years 7 months ago [\#44366](#44366) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#44366 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

I think that the problem comes from the JS error that you have on your website:
Uncaught TypeError: Cannot call method 'set' of null
in the file [ themetrocashcard.com/templates/beez\_20/j...t/md\_stylechanger.js](https://themetrocashcard.com/templates/beez_20/javascript/md_stylechanger.js)

I don't know why you have that error though.
Looking around online, you're not the only one with that js error:
[ stackoverflow.com/questions/9187026/mootools-issue-in-ie8](http://stackoverflow.com/questions/9187026/mootools-issue-in-ie8)
They recommend that you delete that javascript file in order to solve the problem...

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago [\#44537](#44537) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#44537 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

I've fixed the javascript error on the site, but yet again to no avail. [ themetrocashcard.com/component/hikashop/product/cid-11](https://themetrocashcard.com/component/hikashop/product/cid-11) ( the other link above is no good for the purpose of correcting this issue as it has gone live now ) is a link to see that there are indeed no more javascript issues on the page.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

14 years 7 months ago [\#44653](#44653) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#44653 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

Your problem is now basic: You have a default value " " (a space) in your custom field. Because of that, the system understand that something is entered in the custom field and so it doesn't display any error unless you remove the space.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")**
- [![usafadmin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4912.jpg)](/forum/user/4912-usafadmin "View usafadmin's Profile") Topic Author
- [ Offline](/forum/user/4912-usafadmin)

Less More

- Posts: 19
- Thank you received: 0
-
-

14 years 7 months ago -  14 years 7 months ago [\#44727](#44727) by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")  Replied by *[usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#44727 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

DOH!! image missing http://i280.photobucket.com/albums/kk167/Nightfall2003/th_633894166941250845-facepalm.jpg Thank you so much, this issue is now officially resolved. For those that are interested in what the final steps are for this problem here's a breakdown:

1. Create a custom radio button field on the product table. Label it something like 'Required_Participant_Name'. I've set two values, (title)Yes = (value)TRUE, (title)No = (value)FALSE.
2. Create a custom text field on the order table. Label this one something like 'Participant_Name'.
3. Go to Display-&gt;Views modify checkout/fields.php with the following code: Code:

&lt;?php /** * @package HikaShop for Joomla! * @version 1.5.5 * @author hikashop.com * @copyright (C) 2010-2011 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); ?&gt; &lt;?php $cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;loadFullCart(true); $this-&gt;rows =&amp; $cart-&gt;products; $required_participant_name = false; foreach($this-&gt;rows as $row){ $productClass = hikashop_get('class.product'); $product = $productClass-&gt;get($row-&gt;product_id); if($product-&gt;required_participant_name == "TRUE" ) $required_participant_name = true; } if(!$required_participant_name){ $doc =&amp; JFactory::getDocument(); $js="hikashop['reqFieldsComp']['order'] = Array();"; $doc-&gt;addScriptDeclaration( "&lt;!--\n".$js."\n//--&gt;\n" ); return; } ?&gt; &lt;?php if(hikashop_level(2) &amp;&amp; !empty($this-&gt;extraFields['order']) &amp;&amp; $required_participant_name == true){ ?&gt; &lt;div id="hikashop_checkout_additional_info" class="hikashop_checkout_additional_info"&gt; &lt;fieldset class="input"&gt; &lt;legend&gt;&lt;?php echo JText::_('ADDITIONAL_INFORMATION');?&gt;&lt;/legend&gt; &lt;table cellpadding="0" cellspacing="0" border="0" class="hikashop_contentpane"&gt; &lt;?php if(!empty($this-&gt;extraFields['order'])){ JRequest::setVar('hikashop_check_order',1); $this-&gt;setLayout('custom_fields'); $this-&gt;type = 'order'; echo $this-&gt;loadTemplate(); } ?&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div style="clear:both"&gt;&lt;/div&gt; &lt;?php } ?&gt;

4. Find the following file, administrator/components/com_hikashop/classes/field.php. Once located, find the following line of code and comment it out. (Or delete it if you so choose) Code:

if(!$class-&gt;check($fields[$k],$val,@$oldData-&gt;$namekey)){ $ok = false; }

This removes the server side form validation.
5. Bada Boom, Bada Bing - You've now got conditional custom fields. Enjoy!

Nicolas, thanks again!

Last edit: 14 years 7 months ago by [usafadmin](/forum/user/4912-usafadmin "View usafadmin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14282
-
-

12 years 5 months ago [\#158500](#158500) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Conditional Required Fields](/forum/4-how-to/42933-conditional-required-fields#158500 "Heres the issue: My site sells a fundraising product for organizations. Each organization's needs vary, and as such some want to track their sales for individual participants within the group and some...")*

Hi,

Note that conditional custom fields can now be done with the "display limited to" option of the custom fields. No need to change any code.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzQyOTMzLWNvbmRpdGlvbmFsLXJlcXVpcmVkLWZpZWxkcz90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.297 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
