Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Daily Archives: 21/12/2010

Creloaded 6.2 – Call for prices with Product Extra Fields


Create an Extra field ‘Call for prices’ through Creloaded 6.2 backend.
Modify the product_listing.php file by adding the following function at the end of the file.

function getProductsExtraFieldValue($extra_fields_id=4, $products_id){
$ef_value = ”;
$ef_query = tep_db_query(“SELECT `products_extra_fields_value` FROM `products_to_products_extra_fields` WHERE `products_extra_fields_id`='”.$extra_fields_id.”‘ AND `products_id`= ‘”.$products_id.”‘ “);
while ($ef_rows = tep_db_fetch_array($ef_query)) {
$ef_value = $ef_rows[‘products_extra_fields_value’];
}
return $ef_value;
}

The call the function getProductsExtraFieldValue() and do the customization in your need.

$call_for_price = getProductsExtraFieldValue(4,$listing[$x][‘products_id’]);

if ($call_for_price ==”){
$lc_text = $pf->getPriceStringShort();
}else{
$lc_text = ”;
}

Advertisements

Cre Loaded 6.2 – Previous – Next – With detailed info Addons


Previous – Next – With detailed info

1. This contribution places previous/next buttons in the product_info.php page which allows you to navigate the products of that category/manufacturer without having to go back to the category/manufacturer.
2. Optional: the name of the category/manufacturer can be displayed. The category name only is linked back to the category.
3. Optional: there can be buttons to link to the first/last product. These buttons are not supplied. You will have to create them. To insert the code look in the install under Bonus Install.

How to use it:
1. Follow the instructions in the Install Guide for installation
2. All files are located in the folder named files
3. Upload the files to the directories listed in the Install Guide
4. To set where the previous/next buttons will be diplayed go Admin–>Configuration–>Product Listing. Select Location of Prev/Next Bar Location (1-top, 2-bottom, 3-both)

Download Link

Handling array of HTML Form Elements in JavaScript and PHP


Today, I would like to share the way of handling array of HTML FORM elements using JavaScript and PHP.Well, it’s very easy to get the data from the array of HTML form elements in PHP and using them but in JavaScript it’s a bit tricky to handle the array of HTML form elements. I had a hard time to handle them via JavaScript in past thats why I’m posting it here so that people will not have hard time to cope with array of form elements in JavaScript and PHP.

Array of HTML form elements

You can create the array of Form Elements for grouping the similar kind of object or data. The array of elements are very useful in the context where you don’t know how many similar kind of data user have to enter. For example, you have a form where user have to enter his education qualification then you might not know how many of the textboxes are required for a person and in such kind situation you can dynamically generate array of the elements in the form for entering such kind of information.

<input name=”education[]” type=”text” size=”20″ maxlength=”40″ />
<input name=”education[]” type=”text” size=”20″ maxlength=”40″ />
<input name=”education[]” type=”text” size=”20″ maxlength=”40″ />

As you can in the above code, there are array element of textbox defined with the name “education”.Now, let’s see how can we handle them via JavaScript and PHP.
How to handle array of HTML form elements using PHP

If you submit the the the form with the above the array of elements then you can assess it via array of $_POST[‘education’] in PHP. You can use foreach() loop to access the value of the value of these form elements via PHP.

foreach($_POST[‘education’] as $key=>$value)
echo $key.’ ‘.$value;

Normally, posted variable are contained within the POST array but when you post the array of Form Elements then at that time the values are contained within the array of array i.e within $_POST[‘education’] in above exmaple.
How to handle array of Form elements using JavaScript

Handling the array of Form element part is a bit tricky. Now, let try to access the values of the above elements using JavaScript. First, let’s store the above object in a JavaScript variable

var mutli_education = document.form_name.elements[“education[]”];

After storing the object in the variable, we can access the individual variables in the following way in JavaScript

for(i=0;i<mutli_education.length;i++)
{
alert(mutli_education[i].value);
}

As you can see, you can get how many elements are there in the array using the lengh property and you can use the value property to get the value of the indivisual element.

%d bloggers like this: