beanieboy Posted March 12, 2009 Share Posted March 12, 2009 Hi, I have a timetable search form which lets you search for travel options after a time. i.e. search for the next three buses after 3pm to manchester I have a basic html form which submits a post to a php file. The php file takes the postfields and outputs to screen three variables $time1 , $time2 & $time3 . These output three times in 24 hour format. i.e. 12:30 13:45 02:02 What i want to do is basically when i click submit on the previous form, create the same form with the previous details still selected, but with an extra select list with the $time# values in them. Can this be done, i'm not sure how to Thanks Link to comment https://forums.phpfreaks.com/topic/149087-dynamic-form/ Share on other sites More sharing options...
kickstart Posted March 12, 2009 Share Posted March 12, 2009 Hi Yes. Would be pretty easy to do. Just take the values from the $_POST array and put them as values for the input fields when you put the screen out again. The put the time periods out like:- <select name="timeperiod"> <option value="12:30">12:30</option> <option value="13:45">13:45</option> <option value="02:02">02:02</option> </select> All the best Keith Link to comment https://forums.phpfreaks.com/topic/149087-dynamic-form/#findComment-782838 Share on other sites More sharing options...
beanieboy Posted March 12, 2009 Author Share Posted March 12, 2009 ok not sure how i would do that with the way i have my form setup. here's my code below. the php file - scrapes a file from a site using curl and then finds then get the times andd puts them into variables $time1 $time2 $time3. how do i post these back to search.html, or should i create a new form ? ***heres my html form (search.html) *** <form action="formdatanew.php" method="post" name="SearchTicket" id="SearchTicket"> <select name="from.searchTerm" id="from"> <option value="Abbey Wood">Abbey Wood</option> <option value="Aber">Aber</option> <option value="Abercynon North">Abercynon North</option> </select> <select name="timeOfOutwardJourney.day" id="depDayDrop"> <option value="01" selected="selected">1</option> <option value="02">2</option> <option value="03">3</option> </select> <input type="submit" name="Submit" value="Submit" /> </form> *** PHP Form formdatanew.php *** <?php $str2rail = "from.searchTerm=" . $_POST['from_searchTerm'] . "&timeOfOutwardJourney.day=" . $_POST['timeOfOutwardJourney_day'] . "&planjourney=SEARCH"; $URL="http://test3/search"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$URL"); curl_setopt($ch, CURLOPT_COOKIE, $matches[1]); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $str2rail); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // added is needed? curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $times = curl_exec($ch); $cut = explode(" ", $times); $count=count($cut); $stringse = "singleCellwidth\""; $stringse2 = ">"; $stringse3 = ":"; $depcount=0; $dep1=""; $dep2=""; $dep3=""; for($i=0;$i<$count;$i++) { if (strstr($cut[$i],$stringse) == TRUE) { $cut[$i] = ereg_replace( $stringse, "", $cut[$i] ); $cut[$i] = ereg_replace( $stringse2, "", $cut[$i] ); if ($depcount < 4) { if (strstr($cut[$i],$stringse3 ) == TRUE) { $dep[$depcount]=$cut[$i]; print ($dep[$depcount]); print "<br />";print "<br />"; $depcount=$depcount+1; } } } } curl_close ($ch); ?> Link to comment https://forums.phpfreaks.com/topic/149087-dynamic-form/#findComment-782847 Share on other sites More sharing options...
kickstart Posted March 12, 2009 Share Posted March 12, 2009 Hi Crude and fast rewrite:- <?php //*** PHP Form formdatanew.php *** if (isset($_POST['from_searchTerm']) AND isset($_POST['timeOfOutwardJourney_day']) AND !isset($_POST['newtimefield']) { $str2rail = "from.searchTerm=" . $_POST['from_searchTerm'] . "&timeOfOutwardJourney.day=" . $_POST['timeOfOutwardJourney_day'] . "&planjourney=SEARCH"; $URL="http://test3/search"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$URL"); curl_setopt($ch, CURLOPT_COOKIE, $matches[1]); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $str2rail); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // added is needed? curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $times = curl_exec($ch); $cut = explode(" ", $times); $count=count($cut); $stringse = "singleCellwidth\""; $stringse2 = ">"; $stringse3 = ":"; $depcount=0; $dep1=""; $dep2=""; $dep3=""; for($i=0;$i<$count;$i++) { if (strstr($cut[$i],$stringse) == TRUE) { $cut[$i] = ereg_replace( $stringse, "", $cut[$i] ); $cut[$i] = ereg_replace( $stringse2, "", $cut[$i] ); if ($depcount < 4) { if (strstr($cut[$i],$stringse3 ) == TRUE) { $dep[$depcount]=$cut[$i]; print ($dep[$depcount]); print "<br />";print "<br />"; $depcount=$depcount+1; } } } } curl_close ($ch); displayPage($_POST['from_searchTerm'], $_POST['timeOfOutwardJourney_day'], array($time1,$time2,$time3)); } else { displayPage($_POST['from_searchTerm'], $_POST['timeOfOutwardJourney_day']); } function displayPage($from_searchTerm = "", $timeOfOutwardJourney_day = "", $newtimefield = array()) { ?> <form action="formdatanew.php" method="post" name="SearchTicket" id="SearchTicket"> <select name="from.searchTerm" id="from"> <option value="Abbey Wood" <?php echo (($from_searchTerm == "Abbey Wood") ? "selected='selected'" : ""); ?>>Abbey Wood</option> <option value="Aber" <?php echo (($from_searchTerm == "Aber") ? "selected='selected'" : ""); ?>>Aber</option> <option value="Abercynon North" <?php echo (($from_searchTerm == "Abercynon North") ? "selected='selected'" : ""); ?>>Abercynon North</option> </select> <select name="timeOfOutwardJourney.day" id="depDayDrop"> <option value="01" <?php echo (($timeOfOutwardJourney_day == "01") ? "selected='selected'" : ""); ?>>1</option> <option value="02" <?php echo (($timeOfOutwardJourney_day == "02") ? "selected='selected'" : ""); ?>>2</option> <option value="03" <?php echo (($timeOfOutwardJourney_day == "03") ? "selected='selected'" : ""); ?>>3</option> </select> <?php if (count($newtimefield) > 0) { echo "<select name='newtimefield' id='newtimefield'>"; foreach ($newtimefield as $value) { echo "<option value='$value' >$value</option>"; } echo "</select>"; } ?> <input type="submit" name="Submit" value="Submit" /> </form> <?php } ?> Think that is the kind of thing you want (although cannot see where you assign $time1, $time2 & $time3). Note that just putting your $_POST fields into the SQL is not advisable. All the best Keith Link to comment https://forums.phpfreaks.com/topic/149087-dynamic-form/#findComment-782856 Share on other sites More sharing options...
beanieboy Posted March 12, 2009 Author Share Posted March 12, 2009 thanks i'll give a go. sorry had a brainfart. i store the values in $dep# not $time# will let you know. many thanks for your help so far as i'm not a php coder, just someone whos been landed in it Link to comment https://forums.phpfreaks.com/topic/149087-dynamic-form/#findComment-782859 Share on other sites More sharing options...
kickstart Posted March 12, 2009 Share Posted March 12, 2009 Hi That makes it easier. The function is expecting an array there, so you can just pass the array $dep. All the best Keith Link to comment https://forums.phpfreaks.com/topic/149087-dynamic-form/#findComment-782866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.