HighFlyerPL185 Posted May 30, 2013 Report Share Posted May 30, 2013 Hi, I am attempting to pass data in perhaps some kind of a variable to another page where I can actually submit a bid, however I've never extended any modules, and I was wondering if perhaps someone could point me in the right direction, and perhaps explain how passing variables and/or generating templates work? Basically, what I'm setting out to do, is for pilots to complete a form, after they've pressed "Book" in search results. Instead, the current Javascript which adds the bid to the user's record would be moved onto the form. The form would submit information into new columns of phpvms_bids table, once the actual "Book" in the form is pressed. Edit: I had a look at it, so how could I pass $route->id onto another template? (the form) Quote Link to comment Share on other sites More sharing options...
Moderators Parkho Posted May 30, 2013 Moderators Report Share Posted May 30, 2013 Follow these steps: 1. Create a "tpl" file and name it "whatevername.tpl". Your case is the form you're talking about 2. Create a folder and name it "whatevername". 3. Create a file and name it "whatevername.php" 4. Inside the "whatevername.php" write the following code: class whatevername extends CodonModule //whatevername must be exactly the same as the name you created in step 2. { public function index() { $this->render('whatevername.tpl'); //The name of the TPL. } } 4a. Put "whatevername.php" inside "whatevername" folder and upload it into your "core/modules". 4b. Upload "whatevername.tpl" intor your "core/templates" 5. Link the "Book" button to your module using: <a href="<?php echo url('/whatevername') ;?>">Book</a> 6. Now this will get you to the TPL form you just created inorder to pass the values of the fileds you have to use the following form tag: <form action="<?php echo url('/something.php') ;?>" method="post" > //"somthing.php" is the page where you want to proccess passed values. Your case "add bid" <input type="text" name="value1"> <input type="text" name="value2"> <input type="text" name="value3"> . . . <input type="submit" value="submit"> </form> Inorder to pass "$route->id" you need to use the <form> tag and set method to "post": <form action="<?php echo url('your receivingpage') ;?>" method="post"> <input type="hidden" name="id" value="<?php echo $route->id ;?>"> <input type="submit" value="Submit"> </form> then in the other page where you wanna send the id you need to add the following to top of the page: <?php $variable = $_REQUEST['id']; ?> Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 30, 2013 Author Report Share Posted May 30, 2013 Thanks for your reply, Parkho. I've followed these steps, and tried to echo the flight number on the next page, however the flight number is always the same, suggesting that it chooses always the same flight, regardless of whichever I click on. For instance, it's always the first one in the results, in this instance FE9885. <form action="<?php echo url('/Booking') ;?>" method="post"> /* Results Table */ <input type="hidden" name="id" value="<?php echo $route->id; ?>"> <input type="hidden" name="code" value="<?php echo $route->code; ?>"> <input type="hidden" name="flightnum" value="<?php echo $route->flightnum; ?>"> <input type="submit" value="Book"> </form> In the form, I have the following code: <?php $id = $_REQUEST['id']; $code = $_REQUEST['code']; $flightnum = $_REQUEST['flightnum']; ?> <form action="<?php echo url('/schedules/addbid');?>" method="post" > <div class="extended_header"></div> <div class="extended_content"> <table width="100%"> <tr> <td width="25%">Flight Number:</td> <td width="75%"><?php echo $code . $flightnum?></td> </tr> </table> </div> </form> Edit: Just echoed the $id, and it's always 234. Hmm. Quote Link to comment Share on other sites More sharing options...
freshJet Posted May 30, 2013 Report Share Posted May 30, 2013 $id is the schedule ID, not the flight number. Perhaps you mean 'bidid'. Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 30, 2013 Author Report Share Posted May 30, 2013 $id is the schedule ID, not the flight number. Perhaps you mean 'bidid'. I'm trying to understand it atm, but I believe, and of course correct me if I'm wrong, the 'bidid' is generated past the booking? I was looking at the Javascript which triggers the addition of a bid to the system: <a id="<?php echo $route->id; ?>" class="addbid" href="<?php echo url('/schedules/addbid');?>">Book</a> It seems that it adds $route->id, so I guess it would need to be passed onto the form, the remaining details I'd require the user to fill, would be completed in the form, and the data all together would be submitted using the above code, but modified so it's $id instead now. It's merely an extension to the bidding process. I just tried $route->bidid now, and it passes always the first record's ID, regardless of which one I choose to book. I'm beginning to contemplate whether it is down to tablesorter Javascript. Edit: Just got rid of the tablesorter and it did not fix the issue. Quote Link to comment Share on other sites More sharing options...
freshJet Posted May 30, 2013 Report Share Posted May 30, 2013 $route->id is the schedule ID, so that the system knows which flight to book. So yes you are right, the bidid is part of the bid details, not the route. If you are trying to echo the flight number, you should be doing: <?php echo $flightnum;?> Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 30, 2013 Author Report Share Posted May 30, 2013 The flight number is generated correctly. However, like I said, it always passes on the same schedule ID for some odd reason, and does not alter it correctly to the results So, when you click the redirect "Book" link which takes you to the form, It always passes ID 234 to that form. I know this because $flightnum always displays as FE9885. Looking at the database: 234 FE 9885 EGAE EGGP Quote Link to comment Share on other sites More sharing options...
freshJet Posted May 30, 2013 Report Share Posted May 30, 2013 This isn't odd, the schedule ID always remains the same. Each flight has it's own unique ID. I'm not entirely sure on what you need... Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 30, 2013 Author Report Share Posted May 30, 2013 Bare with me, I'm bad at explaining things :L It will always pass on the same $route->id, regardless of which result you click "Book" on. I was contemplating whether I placed the submit button and the inputs outside the foreach, but this isn't the case. If I click "Book" on Flight Number FE9885, it will pass 234 to the next page as $route->id. Equally, it will pass on the same Flight Number, ID and data for other flights, for example if I click "Book" next to FE6000, it will still pass FE9885 and 234 through to the next page. Hope I made more sense now. Edit:// I fixed it by fiddling with the <form> tags order, it didn't like the <form> tags outside of the table column. It's passing it now on fine Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 31, 2013 Author Report Share Posted May 31, 2013 I have now tried adding the form results into new columns of the database. For the time being, I only made one column called "network" in a varchar(25) format. <td> <input type="radio" name="network" value="Offline">Offline<br/> <input type="radio" name="network" value="VATSIM">VATSIM<br/> <input type="radio" name="network" value="IVAO">IVAO<br/><br/> </td> Schedules.php public function addbid() { if(!Auth::LoggedIn()) return; $routeid = $this->get->id; $network = $this->get->network; Further down Schedules.php $ret = SchedulesData::AddBid(Auth::$userinfo->pilotid, $routeid, $network); And finally, inside SchedulesData.class.php public static function addBid($pilotid, $routeid, $network) { $pilotid = DB::escape($pilotid); $routeid = DB::escape($routeid); if(DB::get_row('SELECT bidid FROM '.TABLE_PREFIX.'bids WHERE pilotid='.$pilotid.' AND routeid='.$routeid)) { return false; } $pilotid = DB::escape($pilotid); $routeid = DB::escape($routeid); $network = DB::escape($network); $sql = 'INSERT INTO '.TABLE_PREFIX.'bids (pilotid, routeid, dateadded, network) VALUES ('.$pilotid.', '.$routeid.', NOW(), '.$network.')'; DB::query($sql); self::setBidOnSchedule($routeid, DB::$insert_id); if(DB::errno() != 0) return false; return true; } However, the record isn't saved at all, and I can't understand why. Could it be, because the columns are empty? When I do var_dump($network), it states NULL. It's probably down to the form again, because there is no submit on the link to pass $network through, but I have no idea how to make the link below a type=submit, so it submits the form + $id. <a id="<?php echo $id; ?>" class="addbid btn" href="<?php echo url('/schedules/addbid');?>">Book</a> Quote Link to comment Share on other sites More sharing options...
freshJet Posted May 31, 2013 Report Share Posted May 31, 2013 I have now tried adding the form results into new columns of the database. For the time being, I only made one column called "network" in a varchar(25) format. <td> <input type="radio" name="network" value="Offline">Offline<br/> <input type="radio" name="network" value="VATSIM">VATSIM<br/> <input type="radio" name="network" value="IVAO">IVAO<br/><br/> </td> Schedules.php public function addbid() { if(!Auth::LoggedIn()) return; $routeid = $this->get->id; $network = $this->get->network; Further down Schedules.php $ret = SchedulesData::AddBid(Auth::$userinfo->pilotid, $routeid, $network); And finally, inside SchedulesData.class.php public static function addBid($pilotid, $routeid, $network) { $pilotid = DB::escape($pilotid); $routeid = DB::escape($routeid); if(DB::get_row('SELECT bidid FROM '.TABLE_PREFIX.'bids WHERE pilotid='.$pilotid.' AND routeid='.$routeid)) { return false; } $pilotid = DB::escape($pilotid); $routeid = DB::escape($routeid); $network = DB::escape($network); $sql = 'INSERT INTO '.TABLE_PREFIX.'bids (pilotid, routeid, dateadded, network) VALUES ('.$pilotid.', '.$routeid.', NOW(), '.$network.')'; DB::query($sql); self::setBidOnSchedule($routeid, DB::$insert_id); if(DB::errno() != 0) return false; return true; } However, the record isn't saved at all, and I can't understand why. Could it be, because the columns are empty? When I do var_dump($network), it states NULL. It's probably down to the form again, because there is no submit on the link to pass $network through, but I have no idea how to make the link below a type=submit, so it submits the form + $id. <a id="<?php echo $id; ?>" class="addbid btn" href="<?php echo url('/schedules/addbid');?>">Book</a> OK, I get you now. Can I see the schedule results code? Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 31, 2013 Author Report Share Posted May 31, 2013 The issue has now passed as described above, to the record not saving. I've been fiddling with it all morning but it refuses to work, and I feel it might be just a little stupid mistake or a typo. Anyhow, take a look: schedule_results.tpl sends the variables foreach($allroutes as $route) { ... Table etc. here <form action="<?php echo url('/Booking') ;?>" method="post"> <input type="hidden" name="id" value="<?php echo $route->id; ?>"> <input type="hidden" name="code" value="<?php echo $route->code; ?>"> ... Other inputs </form> } $_REQUEST picks them up on the /Booking page. So I have this code to submit the form, the usual code from phpVMS. Using the code above, to add $network from the form into the database, the record does not get saved: <?php # Don't allow overlapping bids and a bid exists if(Config::Get('DISABLE_SCHED_ON_BID') == true && $route->bidid != 0) { ?> <a id="<?php echo $id; ?>" class="addbid btn" href="<?php echo actionurl('/schedules/addbid');?>">Book</a> <?php } else { if(Auth::LoggedIn()) { ?> <a id="<?php echo $id; ?>" class="addbid btn" href="<?php echo url('/schedules/addbid');?>">Book</a> <?php } } ?> I did some variable dumping, and they're present, hence I'm clueless where I've gone wrong. Schedules.php public function addbid() { if(!Auth::LoggedIn()) return; $routeid = $this->get->id; $network = 'VATSIM'; if($routeid == '') { echo 'No route passed'; echo var_dump($routeid); echo var_dump($network); return; } // See if this is a valid route $route = SchedulesData::findSchedules(array('s.id' => $routeid)); if(!is_array($route) && !isset($route[0])) { echo 'Invalid Route'; return; } CodonEvent::Dispatch('bid_preadd', 'Schedules', $routeid); /* Block any other bids if they've already made a bid */ if(Config::Get('DISABLE_BIDS_ON_BID') == true) { $bids = SchedulesData::getBids(Auth::$userinfo->pilotid); # They've got somethin goin on if(count($bids) > 0) { echo 'Bid exists!'; return; } } $ret = SchedulesData::AddBid(Auth::$userinfo->pilotid, $routeid, $network); CodonEvent::Dispatch('bid_added', 'Schedules', $routeid); if($ret == true) { /*echo 'Booked';*/ echo var_dump($routeid); echo var_dump($network); } else { echo 'Already booked'; } } This returns string(3) "441" string(6) "VATSIM", and the record is not added to the phpvms_bids table. The reason I have added "VATSIM" as a string was to see where the issue is. The normal event would be taking the network variable from the form like this: $routeid = $this->get->id; When I attempt to make the link as a submit button, like this: <form action="<?php echo url('/schedules/addbid');?>" id="bookform" method="post" > .. Actual form went here, and the fields e.g. <td> <input type="radio" name="network" value="Offline"/>Offline<br/> <input type="radio" name="network" value="VATSIM"/>VATSIM<br/> <input type="radio" name="network" value="IVAO"/>IVAO<br/><br/> </td> <a id="<?php echo $id; ?>" onclick="document.getElementById('bookform').submit();" class="addbid btn" href="<?php echo actionurl('/schedules/addbid');?>">Book</a> </form> It will always give me 'No Route Passed' and the id variable will be lost along the way, for some reason (prints out NULL on the next page with var_dump). And the result is the same, if I return back to original files and remove network from the system, it will still do this. But obviously, the form fields need to be somehow submitted. Quote Link to comment Share on other sites More sharing options...
freshJet Posted May 31, 2013 Report Share Posted May 31, 2013 There is a code somewhere to make it non-javascript which is what I use, and when I bid, I am redirected to a confirmation page. Quote Link to comment Share on other sites More sharing options...
HighFlyerPL185 Posted May 31, 2013 Author Report Share Posted May 31, 2013 There is a code somewhere to make it non-javascript which is what I use, and when I bid, I am redirected to a confirmation page. That could be useful. Can you remember the topic title or anything so I could find it quicker? Quote Link to comment Share on other sites More sharing options...
Moderators Parkho Posted June 1, 2013 Moderators Report Share Posted June 1, 2013 Okay! What's going on here!!!!!? Quote Link to comment Share on other sites More sharing options...
freshJet Posted June 1, 2013 Report Share Posted June 1, 2013 That could be useful. Can you remember the topic title or anything so I could find it quicker? http://forum.phpvms.net/topic/7431-no-route-passed-solved/#entry49472 Quote Link to comment Share on other sites More sharing options...
Moderators Parkho Posted June 4, 2013 Moderators Report Share Posted June 4, 2013 When you want to send each flight number separately, you'll need to use a loop through schedules table. The reason the flight number is always the same is because it's not in a loop, so it picks up the first record added in schedules table and pass it on. Quote Link to comment Share on other sites More sharing options...
freshJet Posted June 4, 2013 Report Share Posted June 4, 2013 When you want to send each flight number separately, you'll need to use a loop through schedules table. The reason the flight number is always the same is because it's not in a loop, so it picks up the first record added in schedules table and pass it on. A loop is not required as he is wanting to display the one he clicked book on Quote Link to comment Share on other sites More sharing options...
Moderators Parkho Posted June 4, 2013 Moderators Report Share Posted June 4, 2013 The codes must be in schedules_results.tpl inside the loop in order to pass each flight #, so it's not that a separate loop is required but the one that's already in there. Inside that siply needs a hidden input to pass the flight number to the next page and change the form action to whatever destination BUT withouht a loop it will not work correctly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.