need client side form converts get to a post


J

JRough

By way of explanation, I get a serialized address list output from a
database sent to my local html-javascript client. This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:%22%22;}

I want the local html-javascript client form to convert it to a post
and send it to my php server page. The location.search should get the
one parameter,
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps. I get a response from the php page
but it is not a getting a value for 'q'. I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions. Any help is appreciated,
<html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type ="text/javascript">
var gp=new Array();
var loc=location.search;
if (loc){

loc=loc.substring(1);
var parms=loc.split('&amp;');

for(var i=0;i&lt;parms.length;i++){

nameValue=parms.split('=');
gp[nameValue[0]]=unescape(nameValue[1]);

}

}
var q= gp['q'] ;

</script>
</head>
<body onload="
var frm = document.forms['pgform'];
frm.elements['q'].value = q;
document.forms['pgform'].submit();
">
<form name="pgform" action="http://192.168.1.64/pooglemap2.php"
method="post">
Serialized Address List:
<textarea name="q"></textarea>
<script type ="text/javascript">


</script>
<input type="submit" value="show map">
document.write(q.value);
</form>
</body>
</html
--results from php--
( I need the $addr to have the serialized string in it :-(
setAPIKey("ABQIAAAA9Bwvj_jq9ffNHGrXz9VO7xQcgR4zkW-"); $addr = $_POST
['q']; var_dump($addr); echo "adrr" . "\n\n". "

"; $addrDecode =urldecode($addr); $addrArray= unserialize
($addrDecode); var_dump($addrArray); echo "unserialized" . "\n\n"."

"; foreach($addrArray as $key => $value){ $map->addAddress($value); }
$map->printGoogleJS(); ?> showMap(); ?>
 
Ad

Advertisements

T

Thomas 'PointedEars' Lahn

JRough said:
By way of explanation, I get a serialized address list output from a
database sent to my local html-javascript client. This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:
{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:
%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:
%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:
%22%22;}

Given that much of data to be submitted, you should use a POST request and a
server-side application (may be running local) in the first place. The
maximum URL length in IE is restricted to 2083 characters. (This is not an
issue if your app is never supposed to work with any IE.)
I want the local html-javascript client form to convert it to a post
and send it to my php server page.

form.method = "POST";
form.submit();
The location.search should get the one parameter,

location.search is suited for GET requests, obviously.
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps. I get a response from the php page
but it is not a getting a value for 'q'. I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions. Any help is appreciated,
<html>
<!DOCTYPE html>
<html>

Not Valid, regardless of version and language. <http://validator.w3.org>

Remember: "HTML 5" is only a Working Draft yet. Do not use it by default,
and do not rely on its features, until it has reached REC status and has
been widely implemented (in a few years or so). Otherwise you are going to
face extensive changes in order to be standards-compliant later.
var parms=loc.split('&amp;');

You need to split on `&', not `&amp;'. (Unless you are serving this tag
soup with an XML media type, which I strongly recommend against.)
for(var i=0;i&lt;parms.length;i++){

That is script-syntactically invalid, too. The content model of HTML SCRIPT
elements is CDATA, not PCDATA (even in HTML 5), so you must not escape the
`<' if you want this to work in HTML. A look in the script console would
probably have told you.
gp[nameValue[0]]=unescape(nameValue[1]);

unescape() is not Unicode-safe; most current browsers are. Use
decodeURIComponent() instead.
<form name="pgform" action="http://192.168.1.64/pooglemap2.php"
method="post">

Use host names, not IP addresses. In case 192.168.1.64 is the IP address of
your local Web server, use `localhost' instead (should be aliased to
127.0.0.1 by default).

However, ISTM something is inherently wrong with your approach. Try to
explain what you are going to achieve, basically, instead of posting
questions to your possibly misguided approaches.

<http://jibbering.com/faq/#posting> pp.


PointedEars
 
J

JRough

JRough said:
By way of explanation, I get a serialized address list  output from a
database  sent to my local html-javascript client.  This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:

{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:
%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:
%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:
%22%22;}

Given that much of data to be submitted, you should use a POST request and a
server-side application (may be running local) in the first place.  The
maximum URL length in IE is restricted to 2083 characters.  (This is not an
issue if your app is never supposed to work with any IE.)
I want the local html-javascript client form to convert it to a post
and send it to my php server page.

  form.method = "POST";
  form.submit();
The location.search should get the one parameter,

location.search is suited for GET requests, obviously.
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps.    I get a response from the php page
but it is not a getting a value for 'q'.  I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions.  Any help is appreciated,
<html>
<!DOCTYPE html>
<html>

Not Valid, regardless of version and language.  <http://validator.w3.org>

Remember: "HTML 5" is only a Working Draft yet.  Do not use it by default,
and do not rely on its features, until it has reached REC status and has
been widely implemented (in a few years or so).  Otherwise you are going to
face extensive changes in order to be standards-compliant later.
    var parms=loc.split('&amp;');

You need to split on `&', not `&amp;'.  (Unless you are serving this tag
soup with an XML media type, which I strongly recommend against.)
   for(var i=0;i&lt;parms.length;i++){

That is script-syntactically invalid, too.  The content model of HTML SCRIPT
elements is CDATA, not PCDATA (even in HTML 5), so you must not escape the
`<' if you want this to work in HTML.  A look in the script console would
probably have told you.
        gp[nameValue[0]]=unescape(nameValue[1]);

unescape() is not Unicode-safe; most current browsers are.  Use
decodeURIComponent() instead.
<form name="pgform" action="http://192.168.1.64/pooglemap2.php"
method="post">

Use host names, not IP addresses.  In case 192.168.1.64 is the IP address of
your local Web server, use `localhost' instead (should be aliased to
127.0.0.1 by default).

However, ISTM something is inherently wrong with your approach.  Try to
explain what you are going to achieve, basically, instead of posting
questions to your possibly misguided approaches.

<http://jibbering.com/faq/#posting> pp.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

Hi Thomas
thanks for your post, the output is a get from a desktop database, i
am stuck with that. that is why I have a local file that translates
it to a post. I just need this javascript form to work and i'm done
with the whole thing. I will make the changes you suggest and
repost. I am having to learn javascript in order to get this done.
My approach is a work around with the desktop top database output.
 
J

JRough

JRough said:
By way of explanation, I get a serialized address list  output from a
database  sent to my local html-javascript client.  This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:

{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:
%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:
%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:
%22%22;}

Given that much of data to be submitted, you should use a POST request and a
server-side application (may be running local) in the first place.  The
maximum URL length in IE is restricted to 2083 characters.  (This is not an
issue if your app is never supposed to work with any IE.)
I want the local html-javascript client form to convert it to a post
and send it to my php server page.

  form.method = "POST";
  form.submit();
The location.search should get the one parameter,

location.search is suited for GET requests, obviously.
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps.    I get a response from the php page
but it is not a getting a value for 'q'.  I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions.  Any help is appreciated,
<html>
<!DOCTYPE html>
<html>

Not Valid, regardless of version and language.  <http://validator.w3.org>

Remember: "HTML 5" is only a Working Draft yet.  Do not use it by default,
and do not rely on its features, until it has reached REC status and has
been widely implemented (in a few years or so).  Otherwise you are going to
face extensive changes in order to be standards-compliant later.
    var parms=loc.split('&amp;');

You need to split on `&', not `&amp;'.  (Unless you are serving this tag
soup with an XML media type, which I strongly recommend against.)
   for(var i=0;i&lt;parms.length;i++){

That is script-syntactically invalid, too.  The content model of HTML SCRIPT
elements is CDATA, not PCDATA (even in HTML 5), so you must not escape the
`<' if you want this to work in HTML.  A look in the script console would
probably have told you.
        gp[nameValue[0]]=unescape(nameValue[1]);

unescape() is not Unicode-safe; most current browsers are.  Use
decodeURIComponent() instead.
<form name="pgform" action="http://192.168.1.64/pooglemap2.php"
method="post">

Use host names, not IP addresses.  In case 192.168.1.64 is the IP address of
your local Web server, use `localhost' instead (should be aliased to
127.0.0.1 by default).

However, ISTM something is inherently wrong with your approach.  Try to
explain what you are going to achieve, basically, instead of posting
questions to your possibly misguided approaches.

<http://jibbering.com/faq/#posting> pp.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

I need a javascript html form on the client (local) [only the machine
I am on], to take the output from a desktop database http get url
and convert it to a post to my php server.
 
V

VK

JRough said:
By way of explanation, I get a serialized address list output from a
database sent to my local html-javascript client. This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:%22%22;}

I want the local html-javascript client form to convert it to a post
and send it to my php server page. The location.search should get the
one parameter,
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps. I get a response from the php page
but it is not a getting a value for 'q'. I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions. Any help is appreciated,

As spelled, the problem has no straight cross-browser technical
solution - exactly because of URL limits imposed by IE: from the
"official" 2,083 chars lesser the number of characters in the actual
path http://support.microsoft.com/kb/208427 to some obscure limits up
to 508 chars in some circumstances on some IE versions which are not
too important though to your case.
Any way the URL longer than the limit will lead to the error or it
will be silently truncated depending on IE patch. This way the whole
workaround gets rather pointless: if server response URL is within the
limit then there is no use to bother with GET to POST transformations.
If the server response URL is beyond the limit then IE either errors
out or truncates the URL so your location.href data will be already
non complete so by grabbing it and resending by POST doesn't do
anything good to you.

By itself GET to POST is simple (because you get the form just to
submit it right away, there is no use to bother with textarea, input-
hidden is enough; also decodeURIComponent() is preferred over unescape
() if dealing with parts of URL):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type ="text/javascript">

function Get2Post() {
var frm = document.forms['pgform'];
var q = window.location.search.substring(1).split('=');
frm.elements['q'].value = decodeURIComponent(q[1]);
frm.submit();
}

window.onload = Get2Post;

</script>
</head>
<body>
<form name="pgform"
action="http://192.168.1.64/pooglemap2.php"
method="post">
<input type="hidden" name="q">
</form>
</body>
</html>
 
J

JRough

JRoughwrote:
By way of explanation, I get a serialized address list  output from a
database  sent to my local html-javascript client.  This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:%22%22;}
I want the local html-javascript client form to convert it to a post
and send it to my php server page.  The location.search should get the
one parameter,
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps.    I get a response from the php page
but it is not a getting a value for 'q'.  I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions.  Any help is appreciated,

As spelled, the problem has no straight cross-browser technical
solution - exactly because of URL limits imposed by IE: from the
"official" 2,083 chars lesser the number of characters in the actual
pathhttp://support.microsoft.com/kb/208427to some obscure limits up
to 508 chars in some circumstances on some IE versions which are not
too important though to your case.
Any way the URL longer than the limit will lead to the error or it
will be silently truncated depending on IE patch. This way the whole
workaround gets rather pointless: if server response URL is within the
limit then there is no use to bother with GET to POST transformations.
If the server response URL is beyond the limit then IE either errors
out or truncates the URL so your location.href data will be already
non complete so by grabbing it and resending by POST doesn't do
anything good to you.

By itself GET to POST is simple (because you get the form just to
submit it right away, there is no use to bother with textarea, input-
hidden is enough; also decodeURIComponent() is preferred over unescape
() if dealing with parts of URL):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type ="text/javascript">

function Get2Post() {
 var frm = document.forms['pgform'];
 var q = window.location.search.substring(1).split('=');
 frm.elements['q'].value = decodeURIComponent(q[1]);
 frm.submit();

}

window.onload = Get2Post;

</script>
</head>
<body>
<form name="pgform"
 action="http://192.168.1.64/pooglemap2.php"
 method="post">
<input type="hidden" name="q">
</form>
</body>
</html>
I am doing this in Firefox. I have to get to the bottom of this. It
should work, another person did it and it worked for them. thanks I
will try this out.
 
Ad

Advertisements

J

JRough

JRoughwrote:
By way of explanation, I get a serialized address list  output from a
database  sent to my local html-javascript client.  This is the
string:
file:///Tiger_HD/Library/WebServer/Documents/clientsidepost.html?q=a:4:{i:0;s:49:%2244502%20Loneoak%2C%20Lancaster%2C%20CA%2C%2093534%22;i:1;s:50:%223537%203rd%20St%2C%20Ridgefield%2C%20WA%2C%2098642%22;i:2;s:58:%22931%20Alabama%20St%2C%20san%20francisco%2C%20CA%2C%2094110%22;i:3;s:0:%22%22;}
I want the local html-javascript client form to convert it to a post
and send it to my php server page.  The location.search should get the
one parameter,
the q=xxxxxx and put it in the first array index which I named q then
it should post the q value so I now have a post I can use to plot
address points on google maps.    I get a response from the php page
but it is not a getting a value for 'q'.  I can put the results when I
click submit if you want below or even show you my php page which
works with a get but I need a post because of url length
restrictions.  Any help is appreciated,

As spelled, the problem has no straight cross-browser technical
solution - exactly because of URL limits imposed by IE: from the
"official" 2,083 chars lesser the number of characters in the actual
pathhttp://support.microsoft.com/kb/208427to some obscure limits up
to 508 chars in some circumstances on some IE versions which are not
too important though to your case.
Any way the URL longer than the limit will lead to the error or it
will be silently truncated depending on IE patch. This way the whole
workaround gets rather pointless: if server response URL is within the
limit then there is no use to bother with GET to POST transformations.
If the server response URL is beyond the limit then IE either errors
out or truncates the URL so your location.href data will be already
non complete so by grabbing it and resending by POST doesn't do
anything good to you.

By itself GET to POST is simple (because you get the form just to
submit it right away, there is no use to bother with textarea, input-
hidden is enough; also decodeURIComponent() is preferred over unescape
() if dealing with parts of URL):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type ="text/javascript">

function Get2Post() {
 var frm = document.forms['pgform'];
 var q = window.location.search.substring(1).split('=');
 frm.elements['q'].value = decodeURIComponent(q[1]);
 frm.submit();

}

window.onload = Get2Post;

</script>
</head>
<body>
<form name="pgform"
 action="http://192.168.1.64/pooglemap2.php"
 method="post">
<input type="hidden" name="q">
</form>
</body>
</html>

I am so happy it works! the offset on the serialized list is slightly
off but that is the desktop program. I wonder what the url length
limit is in firefox? This company wanted up to 200 addresses . I
don't see how that is possible in a get even in firefox.
 
V

VK

JRough said:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type ="text/javascript">
function Get2Post() {
 var frm = document.forms['pgform'];
 var q = window.location.search.substring(1).split('=');
 frm.elements['q'].value = decodeURIComponent(q[1]);
 frm.submit();

window.onload = Get2Post;
</script>
</head>
<body>
<form name="pgform"
 action="http://192.168.1.64/pooglemap2.php"
 method="post">
<input type="hidden" name="q">
</form>
</body>
</html>

I am so happy it works!  the offset on the serialized list is slightly
off but that is the desktop program.  I wonder what the url length
limit is in firefox?  This company wanted up to 200 addresses .  I
don't see how that is possible in a get even in firefox.

It may help to go one step back from the point you are working on
right now. That potentially huge URL
clientsidepost.html?q=a:4:{i:0;s:49...
you are getting and resending by POST: this URL with the search part
set is definitely not an Act of Lord :) but a response to some request
initiated from the browser as well. If you describe clearly all steps
from the moment your user launches the browser and up to the moment
she gets the URL like clientsidepost.html?q=a:4:{i:0;s:49... - you
will find out that GET is not needed at all and all client-server
communications get be by POST from the very beginning. Just lay it
down step by step for yourself, post steps description here if need
help.
 
J

JRough

JRoughwrote:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type ="text/javascript">
function Get2Post() {
 var frm = document.forms['pgform'];
 var q = window.location.search.substring(1).split('=');
 frm.elements['q'].value = decodeURIComponent(q[1]);
 frm.submit();
}
window.onload = Get2Post;
</script>
</head>
<body>
<form name="pgform"
 action="http://192.168.1.64/pooglemap2.php"
 method="post">
<input type="hidden" name="q">
</form>
</body>
</html>
I am so happy it works!  the offset on the serialized list is slightly
off but that is the desktop program.  I wonder what the url length
limit is in firefox?  This company wanted up to 200 addresses .  I
don't see how that is possible in a get even in firefox.

It may help to go one step back from the point you are working on
right now. That potentially huge URL
 clientsidepost.html?q=a:4:{i:0;s:49...
you are getting and resending by POST: this URL with the search part
set is definitely not an Act of Lord :) but a response to some request
initiated from the browser as well. If you describe clearly all steps
from the moment your user launches the browser and up to the moment
she gets the URL like clientsidepost.html?q=a:4:{i:0;s:49... - you
will find out that GET is not needed at all and all client-server
communications get be by POST from the very beginning. Just lay it
down step by step for yourself, post steps description here if need
help.

One step back won't help. I have to go one step forward and be done
with this project. I will charge triple for working with anything
that isn't MySQL.

It really is a work around for a desktop app that only has an http
get. I have it all done and I figured out what is wrong. The desktop
app serializes the string but when the url gets sent it adds a %22 to
every parenthesis in the serialized string. So I put in slashes in
the url. It should all work now. All I have to do is figure out
where to call the stripslashes() function before the page loads? I
had another post on this today Friday without the answer.
<head>
<meta http-equiv="Content-Type"

content="text/html; charset=10646-1">
<title>Get to Post Proxy</title>
<script type ="text/javascript">

function Get2Post() {
var frm = document.forms['pgform'];
var q = window.location.search.substring(1).split('=');
frm.elements['q'].value = stripslashes(q[);
//frm.elements['q'].value = decodeURIComponent(q[1]);


//frm.submit();

}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

//window.onload = Get2Post;


</script>

</head>
<body onload= Get2Post()>

<form name="pgform"
action="http://99.20.131.64/pooglemap2.php"
method="post">
<input type="hidden" name="q">
<input type="submit" value="show map">
document.write(q.value);
</form>
</body>
</html>
 
E

Evertjan.

JRough wrote on 31 okt 2009 in comp.lang.javascript:
<input type="hidden" name="q">
<input type="submit" value="show map">
document.write(q.value);
</form>
</body>

Bet you did not test that!
 
J

JRough

JRoughwrote on 31 okt 2009 in comp.lang.javascript:


Bet you did not test that!

Are you speaking about the document.write? I'm just trying to figure
out how to use the firefox debugger and the document.write in order to
find out what is going on. I can figure it out better now I got the
issue solved. It was a workaround and I hope to not get involved in
problems like this in the future but thank you for your input.
 
Ad

Advertisements

E

Evertjan.

JRough wrote on 31 okt 2009 in comp.lang.javascript:

[please do not quote signatures on usenet]
Are you speaking about the document.write? I'm just trying to figure
out how to use the firefox debugger and the document.write in order to
find out what is going on. I can figure it out better now I got the
issue solved. It was a workaround and I hope to not get involved in
problems like this in the future.

It cannot be a workaround if it does not work,
as document.write(q.value); is not HTML, just text.
but thank you for your input

you're welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top