Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Prefill Text Attribute with parameter passed in URL

Prefill Text Attribute with parameter passed in URL

Locked

Views: 6,685

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
25 Sep 2008, 1:01 AM
#1
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Prefill Text Attribute with parameter passed in URL

Hello all, my first post. The FAQs and forums have kept me going pretty well, but now I'm stalled.

I have a need to prefill a text attribute with a parameter passed in on the url of the product_info page.

My customer sells photographs from their historical archives collection. With over 50,000 photographs, having a separate product for each photograph is unrealistic, so I have one Photograph product with an attribute to specify the photo number they want to purchase. The photographs can be searched and viewed from their web site, and I would like a user to be able to purchase a photo by linking directly to the product_info page at http://chessieshop.tracefork.com/index.php?main_page=product_info&cPath=46&products_id=1860 with the Photo Number attribute prefilled for them with the photo number they were viewing.

So I am looking for hints on what zen code do I need to change to allow my zen-cart to accept something like "http://chessieshop.tracefork.com/index.php?main_page=product_info&cPath=46&products_id=1860&PhotoNumber=12345.678"

and then prefill the Photo Number attribute with 12345.678

Thanks,
Lars

27 Sep 2008, 2:01 AM
#2
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Re: Prefill Text Attribute with parameter passed in URL

Never mind, I have a better solution. I created a simple "Add To Cart" form on the photo browser page that includes the attributes I have on my photo product. Now the user can specify the size photo they want to order, hit Add To Cart, and I pass the Photo Number in a hidden input directly to their shopping cart. Works very well, and appears completely seamless to the user.
Lars

23 Jun 2009, 2:42 PM
#3
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: Prefill Text Attribute with parameter passed in URL

Hi,

This is exactly what I've been trying to do but I don't know enough php to make it happen. Could someone fill in the missing steps for me please? Or point me to some online resource and I'll take it from there?

So far I have been looking at a Javascript solution:
http://www.willmaster.com/library/javascript/pre-fill_forms_with_javascript.php

http://www.willmaster.com/blog/javascript/pre-fill-form.php

But "The JavaScript can assign values to type="text", type="hidden", type="password", type="submit", and textarea form fields. Selection and check fields aren't supported."

  1. I need drop down boxes and radio buttons to be controlled with this. Does your method allow it?

  2. Would it make it safer to transfer sensitive data (customer email addresses) by converting it to a cookie before sending it between pages: eg. http://www.willmaster.com/library/javascript/pre-fill-forms-with-lots-of-content.php ?

Thanks in advance guys,

Regards,
shaztesting

23 Jun 2009, 4:09 PM
#4
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Re: Prefill Text Attribute with parameter passed in URL

shaztesting,

I believe my method will work for any attribute type, as I a simply duplicating the zen-cart Add To Cart button. I use it for a drop down and a text field.

You can see an example of a page I create with my Add To Cart button on my Photo Search Page.

View that web page's source and look for the "form name='COHS-1295'" section and see how I pass in the parameters to the drop down 'id[7]' and the text field 'id[txt_8]'.

I came up with the names 'id[7]' and 'id[txt_8]' by looking at the source of my zen-cart product page to see what the attribute field names and id's are on the Add To Cart button. You'll have to do the same for your cart page, as I am certain your zen-cart created names and id's for your products' attributes that are different from mine. Then create a duplicate Add To Cart form on your web page that has all your product's attributes and values included in it.

If you click my Add To Cart button you will go to my zen-cart store and see the product detail page with the Photo Size and Photo Number attributes prefilled.:clap:

I leave the security of personal data to others who claim to know more about it than I do.

23 Jun 2009, 4:55 PM
#5
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: Prefill Text Attribute with parameter passed in URL

Hi Lars,

Thanks for the quick reply and all the help. After spending so long on the javascript solutions I am very excited by the way you have showed me. I will definately try it out over the next few days (or however long it takes me to get it right).

  1. Will this work from any page on the net (e.g Windows2k3 server and an aspx page sending information directly to the cart)? Or only from within one PHP page to another?

  2. Is it is also possible to send the user to the product page and show the prefilled info to allow them to add to cart? (I do understand why you set it up to be hidden and that is quite amazing)

Thanks,
Shaztesting

23 Jun 2009, 5:39 PM
#6
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Re: Prefill Text Attribute with parameter passed in URL

Shaztesting,
Glad you might be able to make use of my solution.

It is just a html form that passes parameters to zen-cart, so it will work from any web page from any browser. Your web server does not get involved with sending info to zen-cart, so it doesn't matter what web server you have creating your pages. The Add To Cart form is going straight from your users' browser to your zen-cart web server, which is specified in the "<form action=..." portion of the Add To Cart form. (For example, my web server cohs.org sends out the Add To Cart button, but when the user clicks that button their request is sent to my zen-cart at chessieshop.com. It appears seamless to the user, but the cohs.org server never communicates directly with chessieshop.com. They are two completely different web servers.)

You can tell zen-cart what attributes to prefill from within the zen-cart admin attribute controller, but changing them on the fly each time you send a user to the Product Detail page from outside zen-cart will require reprogramming the zen-cart php scripts that produce the product detail pages. I'm not very knowledgeable about php or zen-cart's php files, so can't really tell you where to go for that.