2017-06-27 9 views
0

私は比較的簡単なはずだと思うことをしようとしていますが、それを行う方法が正確ではなく、どのようにそれを行うか分からない。フォーム入力を使用して別のURLからデータを取得し、そのデータを読み取る

日付入力フィールドと日(7/14)セレクタを持つフォームがあり、日付または日のいずれかを変更すると、別のURLをクエリして結果を返す必要があります。

私が持っている問題は、次のとおりです。

形式の日付/曜日を選択しますが、ユーザーをリダイレクトするが、URLを読んでから、結果をエコーするページを更新URLを読んでいないためにどのように?

私は私が何を意味するかを示すために一緒に簡単な例を入れている:

<head> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
<link rel="stylesheet" href="/resources/demos/style.css"> 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
<script>$(function() { $("#datepicker").datepicker(); }); </script> 
</head> 
<body> 

<?php 
// Example fully formatted URL 
http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=2017-06-23&days=7 
// http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=[DATESELECTED]&days=[DAYSSELECTED] 
?> 

<form action="http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&" method="GET"> 
<input class="datepicker" type="text" id="datepicker" name="date" value=""> 
<select><option value="7" id="days" name="days">7 days</option><option value="14">14 days</option></select> 
<input type="hidden" name="c" value="3" /> 
<input type="submit" /> 
</form> 
</body> 

<?php 
// Read contents of the URL 
// dateselected = datepicker output 
//$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $days); 
// Display contents of the URL, i.e. 

echo '<hr>'; 
echo 'Show example output that we are trying to achieve using above 
selection but with defaults of date today and days of 7.'; 
echo '<br /><br />'; 
$dateselected = date('Y-m-d'); 
$daysselected = '7'; 
$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $daysselected); 
echo $angelfish; 

//At this point we'll format nicely with coloured rows, etc 
?> 
</body> 

誰かが正しい方向に私を指すことができますか?

多くのおかげで、

ロブ

答えて

2
<pre>Please use below code <?php 
$dateselected = date('Y-m-d'); 
$daysselected = '7'; 
if(isset($_POST['date']) && isset($_POST['days'])){ 
    $dateselected=date('Y-m-d',strtotime($_POST['date'])); 
    $daysselected = $_POST['days']; 
} 
?> 
<head> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
<link rel="stylesheet" href="/resources/demos/style.css"> 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
<script>$(function() { $("#datepicker").datepicker(); }); </script> 
</head> 
<body> 

<?php 
// Example fully formatted URL 
http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=2017-06-23&days=7 
// http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=[DATESELECTED]&days=[DAYSSELECTED] 
?> 

<form name="form1" method="POST"> 
<input class="datepicker" type="text" id="datepicker" name="date" value=""> 
<select name="days"><option value="7" id="days" name="days">7 days</option><option value="14">14 days</option></select> 
<input type="hidden" name="c" value="3" /> 
<input type="submit" /> 
</form> 
</body> 

<?php 
// Read contents of the URL 
// dateselected = datepicker output 
//$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $days); 
// Display contents of the URL, i.e. 

echo '<hr>'; 
echo 'Show example output that we are trying to achieve using above 
selection but with defaults of date today and days of 7.'; 
echo '<br /><br />'; 
echo 'http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $daysselected."<bR>"; 
$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $daysselected); 
echo $angelfish; 

//At this point we'll format nicely with coloured rows, etc 
?> 
</body></pre> 
+1

ジャクソンは、それは華麗だ、私は非常に感銘を受けて、どうもありがとうございました。 –

関連する問題