Option values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Option values

Post by eektech909 »

How can I grab the value of the selected option and make it a string?

I want to add the size with the item name in the add to cart button code.

Code: Select all

echo("    <td valign='top'><select name='selectsize' class='proddetail' tabindex='1' onChange=''>");
echo("      <option value='M'>M</option>");
echo("      <option value='L'>L</option>");
echo("      <option value='XL'>XL</option>");
echo("    </select>    </td>");
and put it where $psize is

Code: Select all

echo("     <input type='hidden' name='item_name' value='" . $pname . " - " . $psize . "'>");
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

$_POST['selectsize'] on the page the form is posted to.
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

I don't send the information to another page, its needs to be used in a later part of the code in the same form.

I'm try to label a hidden input to be the product name(thats grabbed from the database), and add the product size (thats selected in the combobox) to it
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you don't want to send a new http request you have to use a client-side language like javascript.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So the form never submits? Or you post back to itself? Please explain which.
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

I use the information to create the add to cart code that is sent to paypal. I don't receive a response back, i'm just sending it.

Does anyone know how to assign the option value to a php string in a javascript function?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Javascript = Client side.
PHP = Server side.

To get data from the client to the server you need to submit a request (ie form post or querystring page request).
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

Would it be best to post the form to the same page then send the request to paypal after that?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The only way you're going to capture information in a form is to post it, so I would say yeah, post your form, get the posted data, then use it.
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

How do I go about posting the form to the same page, and then posting that information to an external server?

I've been trying to to assign a variable in the onchange field to the selected option. Can that work?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

onChange is something that occurs client side. That means the browser sees it, but the server never does. You can use that, but you are still going to need a page to post to. You can always set the form action attribute value to the name of the page you are on, then check for post in that page and if there are post values, use those to cURL out to the site you want to post to.
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

Alright... i'm pulling my hair out on this.
Heres the code.

Code: Select all

echo("<tr>");
echo("<td>");
echo("<br /><span class='othercontenttitle'>APPAREL</span><br />");
echo("<table width='690' align='0' cellpadding='0' cellspacing ='0' class='contentpdetailbg' align='center'>");
echo("<tr><td class='othercontent'>");
	$prid = ($_GET['pid']);
	$prsku = ($_GET['psku']);
	$productdetail = mysql_query("SELECT * FROM products WHERE prod_id ='" . $prid . "' && prod_sku='" . $prsku . "'");
	$count = mysql_num_rows($productdetail);
	while ($detail=mysql_fetch_array($productdetail)){
		$imgcatid = ($detail["prod_id"]);
		$imgsku = ($detail["prod_sku"]);
		$pname = ($detail["prod_name"]);
		$pdesc = ($detail["prod_desc"]);
		$price = ($detail["prod_price"]);
	echo("<form name='form' target='paypal' action='https://www.paypal.com/...' method='post'>");
	echo("<table width='650' border='0' align='center' cellpadding='0' cellspacing='5'>");
	echo("  <tr>");
	echo("    <td colspan='3' class='proddetailtitle'>");
	 echo("		Product Details	</td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("    <td width='400' rowspan='6'><img src='images/full/" . $imgcatid . "_" . $imgsku . ".jpg' border='0'></td>");
	 echo("    <td height='47' colspan='2' valign='top' class='contentheader'>" . $pname . "</td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("    <td height='142' colspan='2' valign='top' class='proddetail'>" . $pdesc . "</td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("    <td height='29' valign='top' class='proddetail'>Size:</td>");
	 echo("    <td valign='top'><select name='selectsize' class='proddetail' tabindex='1' onChange=''>");
	 echo("      <option value='" . $pname . " - M' selected='selected'>M</option>");
	 echo("      <option value='" . $pname . " - L'>L</option>");
	 echo("      <option value='" . $pname . " - XL'>XL</option>");
	 echo("    </select>    </td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("    <td height='33' valign='top' class='proddetail'>Quantity:</td>");
	 echo("    <td valign='top'><input name='qtyfield' type='text' class='proddetail' tabindex='2' value='1' size='10' />");
	 echo("		  </td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("    <td height='25' valign='top' class='proddetail'>Price:</td>");
	 echo("    <td valign='top' class='proddetail'>$ <b>" . $price . "</b>");
	 echo("		  </td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("    <td width='72' valign='top' class='proddetail'><p>Processing:</p>      </td>");
	 echo("    <td width='158' valign='top' class='proddetail'>ships within 2 business days. orders after 3pm will be processed next day</td>");
	 echo("  </tr>");
	 echo("  <tr>");
	 echo("	<td>&nbsp;</td>");
	 echo("    <td colspan='2'>");  
	 echo("	    <div align='center'>");
	 echo("	      <input type='image' src='images/add_to_cart.gif' border='0' name='submit' alt='Stencil Tee'>");
	 echo("	      <img alt='' border='0' src='https://www.paypal.com/..' width='1' height='1'><br />");
	 echo("	      <input type='hidden' name='add' value='1'>"); ****I NEED THE QUANTITY FROM QTYFIELD HERE INSTEAD OF 1****
	 echo("	      <input type='hidden' name='cmd' value='_cart'>");
	 echo("	      <input type='hidden' name='business' value='accountname'>");
	 echo("	      <input type='hidden' name='item_name' value='PRODUCT'>"); ****I NEED THE SELECTED OPTION VALUE HERE****
	 echo("	      <input type='hidden' name='item_number' value='" . $imgcatid . "_" . $imgsku . "'>");
	 echo("	      <input type='hidden' name='amount' value='" . $price . "'>");
	 echo("	      <input type='hidden' name='no_shipping' value='0'>");
	 echo("	      <input type='hidden' name='no_note' value='1'>");
	 echo("	      <input type='hidden' name='currency_code' value='USD'>");
	 echo("	      <input type='hidden' name='lc' value='US'>");
	 echo("	      <input type='hidden' name='bn' value='PP-ShopCartBF'>");
	 echo("        </div></td>");
	 echo("  </tr>");
	 echo("</table>");
	 echo("</form>");
	}
echo("</td></tr></table>");
echo("</td>");
echo("</tr>");
I need to pull some information from the form to submit to paypal

There noted with ****
Last edited by eektech909 on Mon Jul 02, 2007 11:31 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Where is the QUANTITY and PRODUCT values being set?
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

They decided to drop the QUANTITY option and set it to 1 so never mind that

The PRODUCT is the value of the 'selectsize' selected option (drop-down).

I'm need to get the value of the drop-down box WITHOUT posting the form to a page on wellbornclothing.com..

If its a MUST that I post the form to the same page... (i know how to get the values from the post) how do I send that info to paypal after the page refreshes?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

eektech909 wrote:I'm need to get the value of the drop-down box WITHOUT posting the form to a page on wellbornclothing.com..
Javascript. But you are seriously going to need some contingency plans for folks that have it turned off or disabled.
eektech909 wrote:If its a MUST that I post the form to the same page... (i know how to get the values from the post) how do I send that info to paypal after the page refreshes?
cURL, using the data you already have. Or the Paypal API. They have some pretty good documentation on their webservices.
Post Reply