PDA

View Full Version : Resolved Sending a value to a form from a link



OliveStreet
12-29-2008, 07:33 PM
Moved from the Javascript Forum

Greetings all ....

This may be more of a PHP issue, but I thought I'd start here.

I have an art web site. There will be paintings, jewelry, home decor items, etc. Each item will be highlighted with a short description within a div tag.

I'm also using SSIs for the footer and banner.

What I'd like to do is have one form for item inquiries. From each featured item I would like to have a button/link that can be clicked to make an inquiry. That link would take the person to a form which can then be filled out with name, email, phone, etc. However, I'd really like to have a field pre-populated with an ID from the featured item they just clicked from.

Is there a simple way of doing this? Using php, I'm not sure how to carry the ID value from the featured item and paste it into the value= field in the form.

Thank you for your help

jscheuer1
12-30-2008, 04:48 PM
If you are loading a new page for this form:


link would take the person to a form

it should be done with PHP. Ask in the PHP section for details if the below general explanation isn't enough:

The easiest way would be to have a form send the data.

On your sending page, the form could have radio buttons to determine this value you are sending (radio buttons may be named all of one group, so only one may be checked, and the value passed will be the value of the one checked).

Then the form data could be sent via post or get to the new page, where it is a simple matter in PHP to parse the GET or POST data from the sending form and populate the field on the new page.

Nile
12-30-2008, 04:59 PM
This isn't the safest script....
somefilename.php:


<form action="getSelected.php" method="GET">
<label for="1">Jewelry</label><input type="radio" name="item" value="Jewelry" id="1"/>
<label for="2">Paintings</label><input type="radio" name="item" value="Paintings" id="2"/>
<label for="3">Walls</label><input type="radio" name="item" value="Walls" id="3"/><br />
<label for="4">Ceilings</label><input type="radio" name="item" value="Ceilings" id="4"/>
<label for="5">Carvings</label><input type="radio" name="item" value="Carvings" id="5"/>
<input type="submit" name="submit"/>
</form>


getSelected.php:


<?php
if(isset($_GET['submit'])){
echo "You selected ".$_GET['item'].", right?";
}
?>

OliveStreet
12-30-2008, 11:42 PM
Thanks, Niles. I know this posting got moved to PHP from javascript. I was hoping it could be done with javascript alone, but I guess not. I posted my query in another forum last night and someone sent me a good solution, albeit, done in PHP.

Thanks, again, for your response. I really appreciate your help.

P.S.: I wanted to put a "resolved" next to my post yesterday, but I couldn't figure out how.

Nile
12-30-2008, 11:46 PM
I'm glad to help you anytime.

To put a resolved:
Go to your 1st post, and click edit at the bottom right. Then Click 'Go advanced', next to the thread name there should be a drop down, select 'RESOLVED'.