朋友们,我已经创建了一个表单,并尝试为每个字段设置cookie,我成功为输入文本框设置了cookie,但我没有对textarea字段和下拉列表执行相同的操作。以及复选框。表格如下......
<input name="date" type="text" size="10" value="<?php if(isset($_COOKIE["date"])) echo $_COOKIE["date"];?>" onblur="setCookie(this.name,this.value,60*60*2)" /></td>
Order Number:
<input name="order_num" type="text" size="10" value="<?php if(isset($_COOKIE["order_num"])) echo $_COOKIE["order_num"];?>" onblur="setCookie(this.name,this.value,60*60*2)" />
First Name:
<td><input name="fname" type="text" value="<?php if(isset($_COOKIE["fname"])) echo $_COOKIE["fname"];?>" onblur="setCookie(this.name,this.value,60*60*2)"/></td>
Last Name:
<td><input name="lname" type="text" value="<?php if(isset($_COOKIE["lname"])) echo $_COOKIE["lname"];?>" onblur="setCookie(this.name,this.value,60*60*2)"/>
Image Submitted:
<input name="image" type="text" value="<?php if(isset($_COOKIE["image"])) echo $_COOKIE["image"];?>" onblur="setCookie(this.name,this.value,60*60*2)"/>
General Comments:
<textarea name="gen_comments" cols="50" rows="6" onblur="setCookie(this.name,text,60*60*2)" ><?php if(isset($_COOKIE["gen_comments"])) { echo $_COOKIE["gen_comments"];}?></textarea>
Internal Comments:
<textarea name="int_comments" cols="50" rows="6" onblur="setCookie(this.name,text,60*60*2)"><?php if(isset($_COOKIE["int_comments"])) { echo $_COOKIE["int_comments"];}?></textarea>
Quality of the File:
<select name="quality" onchange="" >
<option >Select One</option><option name="good" value="<?php if(isset($_COOKIE["good"])) echo $_COOKIE["good"];?>">Good</option><option value="ok">A bit low but we can use it</option><option value="low">Low. We are concerned it might effect the qaulity of the final</option><option value="not good">Not good. We cannot work with it</option><option value="test2">test2</option><option value="test">test</option><option value="lkdjfalkdjlaksjdla dlkajsdaksjdlkajsdlkjaslkdjas alksdjaslkdjlaksjdla">Lisa1</option><option value="bbb">aaa</option> <!--option value="good">Good</option>
<option value="ok">A bit low but we can use it</option>
<option value="low">Low. We are concerned it might effect the qaulity of the final </option>
<option value="not good">Not good. We can't work with it</option-->
</select>
<input type="button" name="qofoption" id="qofoption" value="Add New Option"
onClick="optionWindow('http://www.lightaffection.com/Hema2/addnewoption.php?option=qof','optionwindow','400','200')"/> </td>
</tr>
<tr><div name="qofdiv"></div></tr>
<tr>
<td align="right">Image Proportions and Content:</td>
<td colspan="2" style="padding-right:4px">
<select name="imageprop" id="imageprop">
<option>Select One</option><option value="test2">test2</option><option value="not good">Too much details for a Night Light</option><option value="good">Good</option><option value="test">test</option><option value="asdas">asdsa</option><option value="bbb">bbb</option>
<td><b>How would you like us to proceed?</b></td><td></td></tr>
<input type="checkbox" name="proceed_opt[]" value="I will upload new Image">
Insert Option "I will upload new Image"</td></tr>
<tr><td></td><td colspan="2">
<input type="checkbox" name="proceed_opt[]" value="I approve this sample for a Night Light">
Insert Option "<font face="Arial, Helvetica, sans-serif" size="2">I approve this sample for a Night Light</font>" </td></tr><tr><td></td><td colspan="2">
<input type="checkbox" name="proceed_opt[]" value="Select One">
Insert Option "<font face="Arial, Helvetica, sans-serif" size="2">Select One</font>" </td></tr>
<tr><td></td><td colspan='2'>
<input type="checkbox" name="proceed_opt[]" value="other">
Insert Option "Other See comments"</td></tr>
<td> Ship by date: <input name="shipdate" type="text" /><br />
<br />
Update Order Status to: <select name="orderstatus">
<option>Do not change</option>
<option>Waiting for designer</option>
<option>Waiting for customer response</option>
</select>
<br />
<input name="ordermanager" type="checkbox" value="" /> Update Order Manager <br />
<input name="createhtml" type="checkbox" value="" /> Create an HTML page <br />
<input name="sendemail" type="checkbox" value="" /> Send Email to Customer <br /> </td>
</form>
提前感谢..
答案 0 :(得分:1)
关于如何使用PHP设置/读取/删除cookie的简单示例:
<?php
// set a cookie
setcookie("cookiename", "cookievalue", time()+3600);
// read a cookie
if (isset($_COOKIE["cookiename"])) {
$mycookievalue = $_COOKIE["cookiename"];
}
// delete a cookie
setcookie("cookiename", "", time()-3600);
?>
根据您的实际情况,只需重复您需要存储的每个字段。
<强>如,强>
<?php
foreach($_POST as $key =>$value) {
setcookie($key, $value, time()+3600);
}
?>
Cookie语法:
setcookie(name, value, expire, path, domain);
你在哪里可以读到这个:
答案 1 :(得分:0)
要回答您的问题,尽管有更好的方法可以做到这一点:
必须在发送标题之前设置PHP Cookie(在给出任何输出之前,因此您无法按照自己的意愿设置它们)
您可以选择以下选项:
-set the cookies using javascript
-Create a file which acts as the forms action, and in that file pull all the $_POST values and set them there.
但我再说一遍,有更好的方法可以做到这一点。