Inserting List data into form automatically

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 29, 2009   (RSS)

So let's say I have a product (Detail):

http://209.62.14.161/products/buildingsDetail.php?1

The buttons (Click to Rent - Click To Own) Go to the Contact Page.

http://209.62.14.161/contact/index.htm

However, I really need the Product Name to go in the "Product Inquiring about" section on the contact page (It would be even MORE nice if the rent or own box would check as well...)

So, what code do I use to send/receive that information?
I'm currently using:

<a href="../contact/index.htm?subject=<?php echo $buildingsRecord['name'] ?>">

which I know isn't right, but what is the right answer? Is it as simple as replacing "subject" with "form_field_product?"

Thanks all!

Re: [misery217] Inserting List data into form automatically

By Dave - January 28, 2009

Hi misery217,

This is a bit outside the scope of CMS Builder support but here's some tips:

- You can pass values in the url like this: ?name=value

- If you're passing a value from CMS Builder you'll want to url encode it. Instead of <?php echo $record['field'] ?> you'd use <?php echo urlencode($record['field']) ?>

- So your link might look like this:
index.html?product=<?php echo urlencode($record['product']) ?>

- Now, in order to read that value back you're going to need to switch index.htm to index.php.

- Then you could display that value in the field by default like this:
<input name="product" type="text" id="product" size="45" value="<?php echo htmlspecialchars(@$_REQUEST['product']) ?>" />

A few explanations. urlencode() encodes things like space as %20 or + so they work in your urls. Same as you see when you submit a google search where some characters get encoded.

htmlspecialchars() encodes special characters as "html entities" so " becomes &quot; so if your product value had a " in it it wouldn't break your text field (which uses quotes around the value).

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com