- Posts: 19
- Thank you received: 0
Conditional Required Fields
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 or Create an account to join the conversation.
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->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 or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
In the file "fields" of the view "checkout", you can set the default value like that:
if(empty($this->order->Required_Participant_Name)) $this->order->Required_Participant_Name='none';
Please Log in or Create an account to join the conversation.
<?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
*/
defined('_JEXEC') or die('Restricted access');
?>
<?php
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart(true);
$this->rows =& $cart->products;
foreach($this->rows as $row)
{
$productClass = hikashop_get('class.product');
$product = $productClass->get($row->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->product_id)
{
$required_participant_name = $row1;
}
}
}
}
}?>
<?php if(hikashop_level(2) && !empty($this->extraFields) && $required_participant_name=="TRUE"){
hikashop = Array('participant_name');
?>
<div id="hikashop_checkout_additional_info" class="hikashop_checkout_additional_info">
<fieldset class="input">
<legend><?php echo JText::_('ADDITIONAL_INFORMATION');?></legend>
<table cellpadding="0" cellspacing="0" border="0" class="hikashop_contentpane">
<?php
if(!empty($this->extraFields)){
JRequest::setVar('hikashop_check_order',1);
$this->setLayout('custom_fields');
$this->type = 'order';
echo $this->loadTemplate();
}
?>
</table>
</fieldset>
</div>
<div style="clear:both"></div>
<?php } ?>
Please Log in or Create an account to join the conversation.
It should be like that:
Please Log in or Create an account to join the conversation.
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.
Please Log in or Create an account to join the conversation.
Just remove that code:
if(!$class->check($fields[$k],$val,@$oldData->$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 or Create an account to join the conversation.
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
Please Log in or Create an account to join the conversation.
Uncaught TypeError: Cannot call method 'set' of null
in the file themetrocashcard.com/templates/beez_20/j...t/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
They recommend that you delete that javascript file in order to solve the problem...
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
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->Views modify checkout/fields.php with the following code:
5. Bada Boom, Bada Bing - You've now got conditional custom fields. Enjoy!
Nicolas, thanks again!
Please Log in or Create an account to join the conversation.
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 or Create an account to join the conversation.