Forum Moderators: coopster

Message Too Old, No Replies

Using option values as the submit id

         

cybrsrce

10:38 pm on Jan 19, 2009 (gmt 0)

10+ Year Member



I'm trying to add information to an order page and I can't quite figure out what I'm supposed to do.

The page currently uses static submit buttons with a value and id equal to the product people want to buy. It is session based and, based on the value, moves on to the next page.

We have added more options and, instead of polluting the page with unnecessary information, I wanted to add dropdown select fields.

The following is a snipit from the page:

...
if($_POST['1_x'])
{
$_SESSION['temp_pack'] = "1";
header("Location:../register/index.php");
}
...
<form name="frm" id="frm" method="post" action="select.php">
...
<select name="Package">
<option value="">Selecta Package</option>
<option value="1">1st Package</option>
<option value="2">2nd Package</option>
<option value="3">3rd Package</option>
</select>
...

This is the static link to the 1st package that will let you continue:

<input type="image" name="1" src="/templates/<?php echo TEMPLATEDIR; ?>/images/select.png"">

How can I populate name in the input tag with the value from the options?

Any help would be appreciated as I know next to nothing about html and php.

dreamcatcher

1:26 pm on Jan 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi cybrsrce, a warm welcome to WebmasterWorld. :)

Looks like this question is confusing some people, including myself. Sorry. Can`t you just use the value of $_POST['Package'] when you process the form?

I`m just a little unclear at the moment what it is you are trying to do.

dc

cybrsrce

3:18 pm on Jan 20, 2009 (gmt 0)

10+ Year Member



Sorry, it is hard for me to explain as well, I'm a system guy...

This is the first page of an order process. I've been able to change and add a few packages in the past, but the page is getting to be a mess. Each current package is a small graphic with an input image below it - <input type="image" name="(package number 1-11 goes here)" src="/templates/<?php echo TEMPLATEDIR; ?>/images/select.png"">

I'm trying to change it so that a user can select from a dropdown menu but the original coder used the name field in the input to pass the package number to the session.

When I replaced name="1" with name=$_POST['Package'] it returns to the same page.

I tried changing the values to N_x (see below) but it still doesn't go forward. Let me know if I can provide any further information that may make it clearer. Thanks!

More on the session info:

session_start();

if ($_SESSION['usi']!="")
header("Location: /index.php");
else
$_SESSION['usi']="";

$dbObj = new Database();
$dbObj->connect_db();
$fnObj = new Functions();
$_SESSION['step1'] = "step1";
$_SESSION['select_posts'] = "";

$fnObj->csth(true);

extract($_POST);
//print_r($_POST);

if($_GET['temp_pack'])
{
$_SESSION['temp_pack'] = $_GET['temp_pack'];
header("Location:../register/index.php");
}

if($_POST['1_x'])
{
$_SESSION['temp_pack'] = "1";
header("Location:../register/index.php");
}
elseif($_POST['2_x'])
{
$_SESSION['temp_pack'] = "2";
header("Location:../register/index.php");
}
elseif($_POST['3_x'])
{
$_SESSION['temp_pack'] = "3";
header("Location:../register/index.php");
}

coopster

11:11 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm trying to change it so that a user can select from a dropdown menu but the original coder used the name field in the input to pass the package number to the session.

If I understand you correctly, you need to make the <option> value now what used to be the <input> name attribute and modify your server-side code to use the option value returned to populate your SESSION data.

cybrsrce

12:46 am on Jan 22, 2009 (gmt 0)

10+ Year Member



That is correct.

coopster

1:58 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You don't need to "move" the value from the option to the <input> type image as long as the <select> is part of the same form (within the same <form></form> tags). In your processing script, if submit was selected, use the following snippet to dump the POST variables to your display, you'll see what you will need at that point.
print '<pre>'; 
print_r($_POST);
print '</pre>';
exit;