Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-01-2012, 03:07 AM
DustyJoe DustyJoe is offline
 
Join Date: Dec 2007
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help passing variables between templates..

I've been searching for a bit but have not come across anything that really matches my dilemma.

My code probably isn't the greatest as I am learning as I go, please be kind..

Here is where my issue begins, I can read data from my database and pass it to the template to be displayed within a table
Code:
$query = "SELECT * FROM BAMFG_vehicle"; 
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$output .= "<tr><td width=100>".$row['year']."</td><td width=100>".$row['make_model']."</td><td width=20>".$row['vehicle_id']."</td><td width=100><a href='bamfg_vehicle.php?do=delete_vehicle&id=".$row['vehicle_id']."'>DELETE</a></td><td width=100><a href='bamfg_vehicle.php?do=edit_vehicle&id=".$row['vehicle_id']."'>EDIT</a></td></tr>";
}

$templater = vB_Template::create('BAMFG_vehicle');
	$templater->register('navbar', $navbar); 
	$templater->register('output', $output);
print_output($templater->render());
When the template is displayed, the table looks good and the links work well with the URL being listed as:
Code:
http://emycrosoft.com/BAMFG/bamfg_vehicle.php?do=delete_vehicle&id=42
when I click 'DELETE' on vehicle id 42, or whichever other vehicle I click on appears in the url respectively.

What I'm needing to do is pass the vehicle_id variable from the above code to:
Code:
if($_REQUEST['do'] == 'delete_vehicle') {
echo "HOLY CRAP - DELETING VEHICLE";



echo $id;

$templater = vB_Template::create('BAMFG_delete');
	
	$templater->register_page_templates();
	$templater->register('navbar', $navbar); 
	$templater->register('vehicle_id', $vehicle_id);
print_output($templater->render());}
I need the variable passed so I can do another query to pull the rest of the data from the table based upon the vehicle_id for a pop up confirmation I will be working on.

Should I rework the output from the original query to have the links rendered within the template so I an use the $POST command to resubmit the data? and if so, how? I'm currently googling my brains out looking for help!

So, in a nutshell this is the beginning and I've been putting this together through examples and tutorials I've found. I was hoping to get it working then go back through and 'streamline' and get rid of all that is not needed.

Thanks guys..

--------------- Added [DATE]1325390971[/DATE] at [TIME]1325390971[/TIME] ---------------

Parts of the code are not being used yet, as I'm working to through them one by one to get them working..

Here is the full .php file I'm working out of.. remember.. be kind =/
Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'test');
define('CSRF_PROTECTION', true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####


// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######


// **************** ADD VEHICLE ****************
if($_REQUEST['do'] == 'addvehicle') {


$templater = vB_Template::create('BAMFG_addvehicle');
	
	$templater->register_page_templates();
	$templater->register('navbar', $navbar); 
	$templater->register('addvehicle', $addvehicle);
print_output($templater->render());
}


// **************** DELETE VEHICLE ****************
// **************** DELETE VEHICLE ****************
// **************** DELETE VEHICLE ****************
if($_REQUEST['do'] == 'delete_vehicle') {
echo "HOLY CRAP - DELETING VEHICLE";



echo $id;

$templater = vB_Template::create('BAMFG_delete');
	
	$templater->register_page_templates();
	$templater->register('navbar', $navbar); 
	$templater->register('vehicle_id', $vehicle_id);
print_output($templater->render());
	    

}

// **************** SAVE NEW VEHICLE ****************
// **************** SAVE NEW VEHICLE ****************
// **************** SAVE NEW VEHICLE ****************
if($_REQUEST['do'] == 'save_new_vehicle') {

	$results = $db->query_first("SELECT count(*) as cnt FROM " . TABLE_PREFIX . BAMFG_vehicle);
	$vehicle_id_plus = $results['cnt'];
$vehicle_id_plus = $vehicle_id_plus + 1;

echo "$vehicle_id_plus";

$year = $_POST['year'];
$make_model = $_POST['make_model'];
$interior = $_POST['interior'];
$exterior = $_POST['exterior'];
$audio_video = $_POST['audiovideo'];
$wheels_tires = $_POST['wheelstires'];
$suspension = $_POST['suspension'];
$drivetrain = $_POST['drivetrain'];

$sql = "INSERT INTO ". TABLE_PREFIX ."BAMFG_vehicle (
      vehicle_id, 
      userid, 
      year, 
      make_model,
      interior,
      exterior,
      audio_video,
      wheels_tires,
      suspension,
      drivetrain) VALUES (
      '". $vehicle_id_plus ."',
      '". $userid ."',
      '". $year ."',
      '". $make_model ."',
      '". $interior ."',
      '". $exterior ."',
      '". $audio_video ."',
      '". $wheels_tires ."',
      '". $suspension ."',
      '". $drivetrain ."')";
$db->query_write($sql);
}


// **************** EDIT VEHICLE ****************
if($_REQUEST['do'] == 'edit_vehicle') {

echo "HOLY CRAP - I'm EDITING A VEHICLE";

$templater = vB_Template::create('BAMFG_edit');
	
	$templater->register_page_templates();
	$templater->register('navbar', $navbar); 
	$templater->register('vehicle_id', $vehicle_id);
print_output($templater->render());
	    
}



// **************** VIEW VEHICLE ****************







$query = "SELECT * FROM BAMFG_vehicle"; 
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$output .= "<tr><td width=100>".$row['year']."</td><td width=100>".$row['make_model']."</td><td width=20>".$row['vehicle_id']."</td><td width=100><a href='bamfg_vehicle.php?do=delete_vehicle&id=".$row['vehicle_id']."'>DELETE</a></td><td width=100><a href='bamfg_vehicle.php?do=edit_vehicle&id=".$row['vehicle_id']."'>EDIT</a></td></tr>";
}






$templater = vB_Template::create('BAMFG_vehicle');
	$templater->register_page_templates();
	$templater->register('pagetitle', 'Test Page');
	$templater->register('navbar', $navbar); 
	$templater->register('test', $test);
	$templater->register('output', $output);
	$templater->register('my_array', $my_array);
	$templater->register('test_bit_rendered', $test_bit_rendered);
	$templater->register('loop_bit_rendered', $loop_bit_rendered);
print_output($templater->render());

?>
--------------- Added [DATE]1325391107[/DATE] at [TIME]1325391107[/TIME] ---------------

BAMFG_vehicle template:
Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    
    {vb:raw header}
    
    {vb:raw navbar}

    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
    
    <h2 class="blockhead">Title</h2>
    <div class="blockbody">
      <div class="blockrow">
     

VIEW VEHICLE TEMPLATE


<table>
 {vb:raw output}
<tr><td><center><a href="bamfg_vehicle.php?do=addvehicle">Add New Vehicle</a></center></td></tr>
</table>


   


      </div>
    </div>
    
    {vb:raw footer}
  </body>
</html>
BAMFG_delete template
Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    
    {vb:raw header}
    
    {vb:raw navbar}

    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
    
    <h2 class="blockhead">Title</h2>
    <div class="blockbody">
      <div class="blockrow">
     


DELETE VEHICLE TEMPLATE

   {vb:raw output}



<a href="bamfg_vehicle.php">CLICK TO VIEW VEHICLES</a>

      </div>
    </div>
    
    {vb:raw footer}
  </body>
</html>
BAMFG_edit template
Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    
    {vb:raw header}
    
    {vb:raw navbar}

    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
    
    <h2 class="blockhead">Title</h2>
    <div class="blockbody">
      <div class="blockrow">
     


EDIT VEHICLE TEMPLATE





<a href="bamfg_vehicle.php">CLICK TO VIEW VEHICLES</a>

      </div>
    </div>
    
    {vb:raw footer}
  </body>
</html>
Reply With Quote
  #2  
Old 01-01-2012, 03:47 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't have to change it to POST, just do something like this:

Code:
if($_REQUEST['do'] == 'delete_vehicle') {
echo "HOLY CRAP - DELETING VEHICLE";

$vbulletin->input->clean_gpc('r', 'id', TYPE_INT);
$id = $vbulletin->GPC['id'];

...and then next you'll probably want to make sure $id is actually set to a valid id, or at least is an integer >= the min id.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05694 seconds
  • Memory Usage 2,188KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete