Welcome, Guest. Please login or register.
Login with username, password and session length


It's a release candidate! VirtueMart 2.0 RC - the next generation VirtueMart - is available! Read more....

  Advanced search

247038 Posts in 67506 Topics- by 258314 Members - Latest Member: aniketana
VirtueMart ForumOld Stuff, We do not support vm1.0 anymore. This boards are just for readingHow To: Tips & Tutorials VM1.0 (Moderators: deneb, guilliam)[How To] Change a Custom Attribute to display a Text Area instead of a Text Line
Pages: [1] 2   Go Down
Print
Author Topic: [How To] Change a Custom Attribute to display a Text Area instead of a Text Line  (Read 19969 times)
deneb
Moderator
Hero Member
*
Posts: 654


« on: February 23, 2006, 21:13:07 PM »

Have you ever wanted to transform a Custom Attribute from a single text line input box into a multi-line text area?

Custom Attributes 101:
The Custom Attribute feature allows the customer to input additional data along with each item they purchase. This is configured in the Product Form on the 'Product Status' tab. Just type in a Label in the 'Custom Attribute List:' field and VM will display a text box on the Product Details page. You can setup multiple Custom Attributes for any product by entering a list of labels separated by a semi-colon, or ';' like so:

Quote
Name;Extras;...

Getting advaced...
What if you want to replace that text box that is displayed as a single line into a multi-line Text Area so the customer can input a story along with the items purchased?

Here is one way to do this.

First, this requires a little editing of the file that is in charge of displaying the Custom Attrtibutes on the Product Details page
...so back up your file by making a copy.

This How To was written to work with and tested on Joomla 1.0.7 and VirtueMart 1.0.2

ok, open the file: ps_product_attribute.php
location: <site_root>/administrator/components/com_virtuemart/classes/

find the function around line 349 called: list_custom_attribute()

find this line of code around 369:
Code:
$html .= "<input type=\"text\" class=\"inputbox\" id=\"".$titlevar."_field\" size=\"30\" name=\"$titlevar\" />";


with this one:
Code:
$html .= "<TEXTAREA rows=\"5\" cols=\"30\" id=\"".$titlevar."_field\" name=\"$titlevar\"  /></textarea>";

where:
rows is the height of the text area,
cols is the width of the text area.

There are more attributes that can be used with the <textarea> tag which you can explore on your own.

This will change they way VM displays the Custom Attributes... FOR ALL PRODUCTS!

Getting more advanced

Well, what if I don't want all of my Custom Attributes displayed like this, you say?

You can control how Custom Attributes are displayed by adding a little logic to the above example. What I do is test what the Custom Attribute field is named, then display it as a single line textbox or a textarea accordingly.

A little planning here helps! Think of what you want for the label of your texarea Custom Attributes fields. And use that same label throughout your products when you need a TextArea field.

example:
Say you need to collect info from the customer about a product.
Choose a field label called: "Please describe the product in as much detail as possible"

now test for that label every time a Custom Attribute needs to be displayed on Products Details pages.

take the original code line on or around line 369:
Code:
$html .= "<input type=\"text\" class=\"inputbox\" id=\"".$titlevar."_field\" size=\"30\" name=\"$titlevar\" />";

and replace it with this:
Code:
if ( $field != "Please describe the product in as much detail as possible" ) {
$html .= "<input type=\"text\" class=\"inputbox\" id=\"".$titlevar."_field\" size=\"30\" name=\"$titlevar\" />";
}
else {
$html .= "<TEXTAREA rows=\"5\" cols=\"30\" id=\"".$titlevar."_field\" name=\"$titlevar\"  /></textarea>";
}

Now everytime you use "Please describe the product in as much detail as possible" as a Custom Attribute in a product, it will display that as a label along with your cool TEXTAREA.  Grin

You may need to experiment with the layout issues this will cause on the Product Details pages and the Shopping Cart and Emails and Invoices.  Lips Sealed
Logged
pethead
Newbie
*
Posts: 48



« Reply #1 on: February 23, 2006, 21:41:06 PM »

thanks very much Cheesy I am on it
Logged
pethead
Newbie
*
Posts: 48



« Reply #2 on: February 23, 2006, 21:50:56 PM »

I have tested the 2nd one and works fine .. but how could I set a css class for it ?
Logged
pethead
Newbie
*
Posts: 48



« Reply #3 on: February 23, 2006, 21:58:45 PM »

oh i just did it

changed to:
Code:
if ( $field != "Wording Outside" ) {
$html .= "<input type=\"text\" class=\"inputbox\" id=\"".$titlevar."_field\" size=\"30\" name=\"$titlevar\" />";
}
else {
$html .= "<TEXTAREA rows=\"5\" cols=\"30\" class=\"inputbox\" id=\"".$titlevar."_field\" name=\"$titlevar\"  /></textarea>";
}
Logged
deneb
Moderator
Hero Member
*
Posts: 654


« Reply #4 on: February 23, 2006, 22:02:49 PM »

yep, or anyother custom CSS style:

Code:
$html .= "<SPAN class=\"myCSSclass\">";
$html .= "<TEXTAREA rows=\"5\" cols=\"30\" id=\"".$titlevar."_field\" name=\"$titlevar\"  /></textarea>";
$html .= "</SPAN>";
Logged
pethead
Newbie
*
Posts: 48



« Reply #5 on: February 23, 2006, 22:06:04 PM »

ok may I ask the how could this work with 2 different Custom Attribute ?

example:
Custom Attribute List: Wording Outside; Wording Inside

.. and I want both to use a textarea

so ?

thanks alot
Logged
deneb
Moderator
Hero Member
*
Posts: 654


« Reply #6 on: February 23, 2006, 22:12:04 PM »

the simple way to do that is to change the IF statement test...

in your case:

Code:
if ( $field != "Wording Outside" || $field != "Wording Inside" ) {
Logged
pethead
Newbie
*
Posts: 48



« Reply #7 on: February 23, 2006, 22:19:23 PM »

hm...

something goes wrong with "Wording Inside" generally, even if I test this:
Code:
if ( $field != "Wording Inside" ) {
$html .= "<input type=\"text\" class=\"inputbox\" id=\"".$titlevar."_field\" size=\"30\" name=\"$titlevar\" />";
}
else {
$html .= "<TEXTAREA rows=\"5\" cols=\"30\" class=\"inputbox\" id=\"".$titlevar."_field\" name=\"$titlevar\"  /></textarea>";
}

weird
Logged
pethead
Newbie
*
Posts: 48



« Reply #8 on: February 23, 2006, 22:25:56 PM »

yeap I have tested everything and using:
Code:
if ( $field != "Wording Outside" || $field != "Wording Inside" ) {
$html .= "<input type=\"text\" class=\"inputbox\" id=\"".$titlevar."_field\" size=\"30\" name=\"$titlevar\" />";
}
else {
$html .= "<TEXTAREA rows=\"5\" cols=\"30\" class=\"inputbox\" id=\"".$titlevar."_field\" name=\"$titlevar\"  /></textarea>";
}

..things apear as if it was not set at all your way
Logged
deneb
Moderator
Hero Member
*
Posts: 654


« Reply #9 on: February 24, 2006, 11:50:37 AM »

if you put text in the IF statement, then you must use the exact same in your Custom Attribute....without spaces...

Quote
Wording Outside;Wording Inside

try this IF statement with the ampersands instead:
Code:
if ( $field != "Wording Outside" && $field != "Wording Inside" ) {
Logged
pethead
Newbie
*
Posts: 48



« Reply #10 on: February 25, 2006, 11:22:32 AM »

yeah works fine now

thanks very much deneb for this, ...
Logged
rexel99
Newbie
*
Posts: 4


« Reply #11 on: April 28, 2006, 00:42:01 AM »

Great option but I have a slightly different requirement that I think could be done in the same area, hoping you can help with the code that would be required.

What I need is Date and/or Time text entry (as in using the Custom Attributes) but with a java date/time picker function. I am looking at using something like;
http://www.dynamicdrive.com/dynamicindex7/jasoncalendar.htm
(perhaps there are other suggestions too)

However looking at your mods above, inserting this would bring it up for each and any textbox/area.

What i want to know if it's possible to put in an 'If' statement such as... (in my programming english)

If Field,$custom_attr_list = "Date" then;
  Append DatePicker Java Code after text field with DATE parameters
If Field,$custom_attr_list = "Time" then;
  Append DatePicker Java Code after text field with TIME parameters
End if

It's beyond me to mod the script this far, so any code samples you can provide to do this would really be appreciated.

Thanks in advance,
Regards Rex.
Logged
Beron
Newbie
*
Posts: 7


« Reply #12 on: May 21, 2006, 10:02:24 AM »

Deneb : Thanks!

Works with Joomla 1.0.8 and VirtueMart 1.0.5 as well.

My php knowledge is close to zero im afraid but it seems to me that this approach could also be used for making a "price pr. letter" hack using letters as a product or child product and  an unique name for the textbox.

When the customer clicks add to cart, update the letter product quantity according to what the customer typed in the textbox (stripped for white space).

Is this possible without a lot of code?

Excuse my english. A bit clumsy explained i think...
Logged
Beron
Newbie
*
Posts: 7


« Reply #13 on: May 21, 2006, 10:06:34 AM »

Maybe even more user friendly with an uniqe name for a drop down as well and using text types with prices in the dropdown, and then multiply the drop down amount with the text length in the textbox.
Then the users are not forced to use letters as products.
Logged
barnett
Jr. Member
**
Posts: 92



WWW
« Reply #14 on: June 30, 2006, 14:34:16 PM »

Check out my new Hack for Custom Attributes Extended.  It does this and more.

http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=19716.msg47166#msg47166

-barnett
Logged

Pages: [1] 2   Go Up
Print
Jump to: