Page 1 of 2
post method
Posted: Tue Nov 07, 2006 10:17 am
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.
Posted: Tue Nov 07, 2006 11:41 am
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];
?>
Posted: Tue Nov 07, 2006 12:13 pm
by garry27
feyd | Please use 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
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]
Posted: Tue Nov 07, 2006 12:16 pm
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');
Posted: Tue Nov 07, 2006 12:21 pm
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');";
Posted: Tue Nov 07, 2006 12:21 pm
by Burrito
you need to separate your variables with an ampersand (&).
Posted: Tue Nov 07, 2006 11:54 pm
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',
Posted: Wed Nov 08, 2006 12:36 am
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.
Posted: Wed Nov 08, 2006 12:48 am
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.
Posted: Wed Nov 08, 2006 1:16 am
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.
Posted: Wed Nov 08, 2006 2:03 am
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:
Posted: Wed Nov 08, 2006 2:24 am
by volka
and
Code: Select all
echo "<pre>\nfilter: ", htmlentities($filter), "</pre>\n";
?
Posted: Wed Nov 08, 2006 2:34 am
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.
Posted: Wed Nov 08, 2006 2:37 am
by volka
It doesn't print anything? Blank page? Then maybe there's a parse error in your script.
Posted: Wed Nov 08, 2006 2:47 am
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!).