Click to See Complete Forum and Search --> : Is there any way to do this?


kindra
03-25-2003, 09:37 AM
I have a form with a textfield and a button, the button should send the variable catched in the textfield to "ficha.php", and should open this page with the common features supported by MM_openBrWindow.
The bad thing: variable is missing....:mad:

Here U have the code, any hints?

<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<form name="referencia" action="ficha.php" target="ficha">
<input type="text" name="varid" class="B">
<input type="button" value="Consultar" onClick="MM_openBrWindow('ficha.php','ficha','scrollbars=yes,width=650,height=550')">
:confused:

tim_gor
03-25-2003, 10:00 AM
I don't know about PHP and am not sure I fully understand the question, but I guess the gist of it is that you want to send the variables from a form on one page to another page?

A couple of solutions spring to my mind
1. Cookies -- Can store the variables in a cookie then retrieve it in the next page

2. I tend to not like cookies and just send small variables in the URL: i.e.
window.open("myurl.htm?someStringThatCanBeParsedIntoData","window","parameters")

you can then retrieve the data in the next page by accessing the variable
(window.location.href), finding where the "?" appears and getting the data out by taking a substring.

Well.. that's just my javascript way of doing things...! No idea about PHP!

kindra
03-25-2003, 10:34 AM
A little problem:
If I send the variable via URL it works, but, the variable doesn´t exist till the moment the user writes it down in the textfiled. I guess the kind of variable I can send via URL is the kind -ficha.php?var=XXXX- the problem is that I can't give any value to this variable because is given by the user.

kindra
03-25-2003, 10:34 AM
A little problem:
If I send the variable via URL it works, but, the variable doesn´t exist till the moment the user writes it down in the textfiled. I guess the kind of variable I can send via URL is the kind -ficha.php?var=XXXX- the problem is that I can't give any value to this variable because is given by the user.

Nedals
03-25-2003, 01:08 PM
You could try it this way..

<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
var URL = theURL + "?" + document.referencia.varid.value;
// The new window will call your ficha.php. You don't need to call it with the FORM action
// The varid value will be accessable to your .php script via a query_string
window.open(URL,winName,features);
}
//-->
</script>
<form name="referencia">
<input type="text" name="varid" class="B">
<input type="button" value="Consultar" onClick="MM_openBrWindow('ficha.php','ficha','scrollbars=yes,width=650,height=550'
)">

kindra
03-25-2003, 04:02 PM
It really works, thank U!
Is it possible to give a name to those variables?
(Now they cross as a pure value)
(For the case in which U want to handle some not only one)

Nedals
03-25-2003, 06:17 PM
Is it possible to give a name to those variables?
Change this line...
var URL = theURL + "?" + document.referencia.varid.value;

to...
var URL = theURL + "?varid=" + document.referencia.varid.value;

Happy to hear it worked. :D

kindra
03-25-2003, 07:31 PM
I have been trying like this, and it works fine too.
The only new problem is that some of the variables have spaces and some of the URL unfriendly characters.
I have tried to catch them from PHP using "urldecode" but it seems like the information is cutted and finished whenever is a space, so I can not recover it.
For variable 'envio1=Gran Avenida' I only get 'envio1=Gran'

Jona
03-25-2003, 07:34 PM
You could try splitting it and making all spaces into underscores:

var URL = theURL + "?varid=" + document.referencia.varid.value;

URL=URL.split(' ').join('_');

Nedals
03-25-2003, 07:59 PM
In javascript, build a query string and 'escape' it

queryStr = "name=value&name=value..etc";

then..
var URL = theURL + "?"+ escape(queryStr);

Depending on how you proess this in PHP, you may have to 'unescape' the string in your PHP script.

kindra
03-25-2003, 08:01 PM
I used that trick but now I get only 1 result, instead 7, like before. Some concatenation problem?

var URL = theURL + "?" + document.referencia.varid.value + "?envio1=" + document.form1.envio1.value;URL=URL.split(' ').join('+'); + "?envio2=" + document.form1.envio2.value;URL=URL.split(' ').join('+'); + "?envio3=" + document.form1.envio3.value;URL=URL.split(' ').join('+'); + "?envio4=" + document.form1.envio4.value;URL=URL.split(' ').join('+'); + "?envio5=" + document.form1.envio5.value;URL=URL.split(' ').join('+'); + "?envio6=" + document.form1.envio6.value;URL=URL.split(' ').join('+');;

kindra
03-25-2003, 08:08 PM
OK, I'm so stupid, I didn't notice the bunch of ;;;;;
Anyway, it doesn't work as it shoulds, I still get only part of the variables in the PHP, even using urldecode...
For variable 'envio1=Gran Avenida' I only get 'envio1=Gran'

Nedals
03-25-2003, 08:09 PM
You only use one '?' and '&' to join each name/value pair

var queryStr =
"envio1="+ document.form1.envio1.value +
"&envio2=" + document.form1.envio2.value +
"&envio3=" + document.form1.envio3.value +
"&envio4=" + document.form1.envio4.value +
"&envio5=" + document.form1.envio5.value +
"&envio6=" + document.form1.envio6.value;
(all one line)

var URL = theURL + "?" + escape(queryStr);

Jona,
I'm pretty sure that the '_' char also needs to be url-encoded, so don't use that method.

Jona
03-25-2003, 10:01 PM
Jona,
I'm pretty sure that the '_' char also needs to be url-encoded, so don't use that method.

Oh... It was just a suggestion. I don't do this kind of work normally. I don't think that _ is encoded, though, because you can have your_name.com and it will work... Right?

Nedals
03-25-2003, 10:11 PM
I did a little checking and '_' is OK! :) or maybe :o

Jona
03-25-2003, 10:21 PM
Did I ever tell you I wasn't stupid? :D Just kidding... hehe