登录 | 注册 | FAQ
Anonymous

Passing form data to a cookie using php

+ 发表回复

3 篇帖子 分页: 1 / 1


Passing form data to a cookie using php

nkibai » 周三 10月 22, 2014 11:35 am

Hi everyone;

I am a newbie to php, and am struggling to get data from a form, and pass it to a cookie to be store temporarily while the customer continues to browse the site.

When the customer finishes, they will go to the order page where there will be a shopping cart, listing all data that has been selected by the customer and are stored in the cookie.

Here is my code for the form:

<form id="product_area" action="order.php" method="post" name="myForm" onsubmit="return(validate());">

<p class="font-size"><font color="red">Please click on the pull-down buttons to select the product id, product name and the quantity you would like to order, and
click the <font color="blue"><b>"Press to Continue"</b></font> button to continue.</font></p>

<div>
<label for="product"><p class="font-size"><font color="blue"><b>Product Code:</b></font></p></label>
<select name="productID">
<option value=""></option>
<option value="Old Man Saltbush">1011 Old Man Saltbush</option>
<option value="Lemon Flowered Gum">1021 Lemon Flowered Gum</option>
<option value="Desert Oak">1031 Desert Oak</option>
<option value="Bottlebrush">1041 Bottlebrush</option>
</select>
</div>

<div>
<label for="quantity"><p class="font-size"><font color="blue"><b>Quantity:</b></font></p></label>
<input id="quantity" name="quantity" type="number" min="0" step="1" value="" id="quantity">
</div>

<div>
<label for="price"><p class="font-size"><font color="blue"><b>Price:</b></font></p></label>
<select name="price">
<option value="20">$20.00</option>
<option value="25">$25.00</option>
<option value="30">$30.00</option>
<option value="35">$35.00</option>
</select>
</div>

<div id="submit">
<input type="submit" value=" Press to Continue ">&nbsp;&nbsp;
<input type="reset" value = "Clear">
</div>

</form>

Some-one help direct me in the right direction.

Thank in advance.
头像

nkibai

  • 帖子: 2
  • 注册: 周三 10月 22, 2014 11:04 am

Re: Passing form data to a cookie using php

XainPro » 周一 10月 27, 2014 7:23 am

on order.php page you can save data in cookie for temporary use by using code like this

setcookie("NameOfCookie", $_POST['name-of-input-field-you-want-to-save'], time()+3600);

for detail understanding about how cookies work you should check out this chapter on cookies.

http://html.net/tutorials/php/lesson13.php
头像

XainPro

  • 帖子: 3933
  • 注册: 周五 2月 17, 2012 8:10 pm

Re: Passing form data to a cookie using php

nkibai » 周一 10月 27, 2014 8:25 am

Thanks XainPro for your reply

Much appreciated
头像

nkibai

  • 帖子: 2
  • 注册: 周三 10月 22, 2014 11:04 am


+ 发表回复

分页: 1 / 1