douyan8266 2012-05-03 17:22
浏览 34

记住表单字段值

Can anyone help me edit this page to remember the form values? I think I need to use cookies? Ive searched this question in alot of places but because I have already got scripts in place that change certain aspects of my page I am having trouble working it out.

<html>
<head>
<title>Laterooms App</title>
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width; initial-scale = 1.0; maximum-scale=1.0; user-scalable=no" />
<style type="text/css">
*{margin:2;padding:0}
html, body {width:320;overflow:hidden}
</style>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function submitForm(s) {
s.value = " Loading... ";
return true;
}
// End -->
</script>
<script type="text/javascript">
function changeImg(img, newimg) {
img.src = newimg;
}
</script>

<center>
<form name=myform onSubmit="return submitForm(this.submitbutton)">
<img src="laterooms.jpg"><br><br>
<input type=text value="Destination" name=title onclick="this.value = '';">
<br>Date:<br>
<select name="month">
    <option value="1">January
    <option value="2">February
    <option value="3">March
    <option value="4">April
    <option value="5">May
    <option value="6">June
    <option value="7">July
    <option value="8">August
    <option value="9">September
    <option value="10">October
    <option value="11">November
    <option value="12">December
</select>
<select name="day">
    <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
    <option value="8">8
    <option value="9">9
    <option value="10">10
    <option value="11">11
    <option value="12">12
    <option value="13">13
    <option value="14">14
    <option value="15">15
    <option value="16">16
    <option value="17">17
    <option value="18">18
    <option value="19">19
    <option value="20">20
    <option value="21">21
    <option value="22">22
    <option value="23">23
    <option value="24">24
    <option value="25">25
    <option value="26">26
    <option value="27">27
    <option value="28">28
    <option value="29">29
    <option value="30">30
    <option value="31">31
</select>
<select name="year">
    <option value="2012">2012
    <option value="2013">2013
    <option value="2014">2014
</select>
<br><br>
No. of Nights:
<select name="nights">
    <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
    <option value="8">8
    <option value="9">9
    <option value="10">10
    <option value="11">11
    <option value="12">12
    <option value="13">13
    <option value="14">14
    <option value="15">15
    <option value="16">16
    <option value="17">17
    <option value="18">18
</select>
<input type=submit name=submitbutton value="Submit"><br>
Please be patient<br>while your results load.
<hr color="#401485">
<?php

$url = "http://xmlfeed.laterooms.com/index.aspx?aid=1000&rtype=4&kword=".$_GET['title']."&sdate=".$_GET['year']."-".$_GET['month']."-".$_GET['day']."&nights=".$_GET['nights']."&orderby=hoteldistance&sortorder=asc";

$xml = simplexml_load_file($url);

foreach($xml->hotel as $hotel)
{

echo "<p>";
echo "<img src=".$hotel->images." height=100 width=100><br/>";
echo "<strong>Hotel Name:</strong><br> ".$hotel->hotel_name."<br/>";
echo "<strong>Prices From:</strong> &pound;".$hotel->prices_from."<br/>";
echo "<a href=".$hotel->hotel_link."><img src=http://affiliates.laterooms.com/AffiliateImages/en/buttons/more_details1.gif onclick=this.src='loading.gif'></a><br/>";
echo "<strong>Miles from ".$_GET['title']."</strong> ".$hotel->hotel_distance."<br/>";
echo "</p><hr color=#401485>";

}
?>

</form> 
</center>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • dqfwcj0030 2012-05-04 14:32
    关注

    You can assign the values by adding the post values to the HTML values like this:

    <input type=text value="Destination" name=title onclick="this.value = '';" value="<?php echo $_POST['title'] ?>">
    

    You can set the value="" for each input on your form with the corresponding input name. When the page is posted, the $_POST array contains the values that you just submitted and therefore you can assign it to the proper input tags value.

    Hope that helps you to better understand how form memory works in PHP.

    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)