post method

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

post method

Post by garry27 »

is it possible to $_POST/$_GET an input box value from inside a script decalred via a headers? ie

a.html b.php c.php

<form action='b.php' <script ... src='c.php' /script> $_POST[$name]
method='post'>
<input box
name ='pool'
value='true'
...submit


previously i had the contents of c.php as a function which was called in b.php but having reworked the code, i have been unable to reclaim the values in the html.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I am not exactly clear what you are trying to do, but perhaps echo() is what you are looking for:

Code: Select all

<?php
include 'c.php'
echo $_POST[$name];
?>
(#10850)
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i'm trying to get input values from a html page to a php/javascript script via a php script that calls the php/javascript script. 

i figure i'd probably need to pass the values in the url that calls the script, so i added the following to the intermediary script:

Code: Select all

$query_string = 'dj=' . urlencode($dj) .  'liveMusic='  . urlencode($liveMusic) 
                . 'kidsZone='  . urlencode($kidsZone) . 'lateLice='  . urlencode($lateLice) 
				. 'nsArea='  . urlencode($nsArea) . 'food='  . urlencode($food) 
				. 'garden='  . urlencode($garden) . 'skySport='  . urlencode($skySport) 
                . 'cocktail='  . urlencode($cocktail) . 'pool=' . urlencode($pool);
   //third parameter outputs script to header
  echo xhtmlheader('Create Pub Crawl', 'KEY', 'map_data2.php?'.htmlentities($query_string), 'mapFunctions.js');
but i still get empty values


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

sorry missed out a php tag in previous post

Code: Select all

$query_string = 'dj=' . urlencode($dj) . 'liveMusic=' . urlencode($liveMusic) 
. 'kidsZone=' . urlencode($kidsZone) . 'lateLice=' . urlencode($lateLice) 
. 'nsArea=' . urlencode($nsArea) . 'food=' . urlencode($food) 
. 'garden=' . urlencode($garden) . 'skySport=' . urlencode($skySport) 
. 'cocktail=' . urlencode($cocktail) . 'pool=' . urlencode($pool); 
//third parameter outputs script to header 
echo xhtmlheader('Create Pub Crawl', 'KEY', 'map_data2.php?'.htmlentities($query_string), 'mapFunctions.js');
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

OK, I am guessing that you want to output Javascript. If not you would use the PHP header() function and then you need to follow the HTTP spec for what you output.

Javascript is output just like you would output HTML, so put double quotes around it so your $query_string variable is expanded and make sure and double quotes are escaped (you seem to have only single quotes) and make sure the Javascript lines have semi-colons too:

Code: Select all

echo "xhtmlheader('Create Pub Crawl', 'KEY', 'map_data2.php?'.htmlentities($query_string), 'mapFunctions.js');";
Last edited by Christopher on Tue Nov 07, 2006 12:23 pm, edited 1 time in total.
(#10850)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you need to separate your variables with an ampersand (&).
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

xhtmlheader() is a php function of mine in the intermediary page. when its called, it passes parameters that are inputted into an html header.

Burrito, i've now added ampersand. thanks for that. but i'm still not getting the results i need. am i adding the third parameter incorrectly?

Code: Select all

echo xhtmlheader('Create Pub Crawl', 'KEY', 'map_data2.php?'.htmlentities($query_string), 'mapFunctions.js'); //'map_data.php',
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

garry27 wrote:

Code: Select all

echo xhtmlheader('Create Pub Crawl', 'KEY', 'map_data2.php?'.htmlentities($query_string), 'mapFunctions.js'); //'map_data.php',
What does it print? Please provide example output.
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

it prints:

Code: Select all

<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
                <head>
<link href='perfectpubcrawl.css' rel='stylesheet' type='text/css'/> 
<SCRIPT language=JavaScript src= ' http://maps.google.com/maps?file=api&am ... xxxxxxxxx' ></SCRIPT> 
<SCRIPT language=JavaScript src= ' map_data2.php?dj=&liveMusic=&kidsZone=true&lateLice=true&nsArea=true&food=&garden=&skySport=&cocktails=&pool= ' ></SCRIPT> 
<SCRIPT language=JavaScript src= ' mapFunctions.js ' ></SCRIPT><meta http-equiv='Content-Type' 
                    content='text/html; 
                    charset=utf-8' />
                   <title>Create Pub Crawl</title>
		        </head>
the input values stem from checkboxes with a value of 'true'. obv if their unchecked when their submitted, they don't return anything.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

garry27 wrote:the input values stem from checkboxes with a value of 'true'. obv if their unchecked when their submitted, they don't return anything.
Yes, that's how it works, see http://www.w3.org/TR/html4/interact/for ... l-controls
Your script can test the absence of a parameter via isset().
you should remove the leading blanks from your src attributes.
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

hi, thanks for the advice. i'm having problems now collecting the data sent to map_dat2.php (the php <script>).

i'm trying to use the following code to create a php stringvariable, $filter. this code worked before i moved it from a standard php page. as it is now, i can't can't output the values in $filter without it screwing the script.

Code: Select all

$chkbox_arr = array ( 'dj', 'liveMusic', 'nsArea','food','skySport', 'cocktails'
		   ,'pool', 'garden', 'lateLice', 'kidsZone' );
  //filter out unchecked boxes 
  for ( $i = 0; $i <10; $i++ ) {
    $element = $chkbox_arr[$i];
    if ( !isset( $_GET[$element] ) ) {
	  unset( $chkbox_arr[$i] );
}
  }
  // re-sort index and count number of elements 
  sort ($chkbox_arr);
  $result = count($chkbox_arr);
  //add sql string to each element
  for ( $i = 0; $i <$result; $i++ ) {
    $chkbox_arr[$i]=' AND Amenities.'.$chkbox_arr[$i]."='y'";
  }
   
  // create string of all elements 	
  $filter = implode(" ", $chkbox_arr ); 
/////// ...this will then be used to add to the mysql query
outputing $filter to jscript like this messes the script up and doesn't display the alert box:

Code: Select all

print  "alert('" .$filter ."');";
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and

Code: Select all

echo "<pre>\nfilter: ", htmlentities($filter), "</pre>\n";
?
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

that doesn't return anything. the previous block of code i posted is from the external php script that's declared in a header.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It doesn't print anything? Blank page? Then maybe there's a parse error in your script.
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

no, i mean the page that calls the script loads properly (ie shows the right html and map coordinates contained on a separate .js file). however, the php script that is called in the header doesn't return/output anything (no markers for my map, alert box, errors, nothing!).
Post Reply