Hello
I use a mail()-feedback creating a html-mail on one page. The $textbody contains the html-code with all variables of the formular, trivial so far. But I want to get the user's screen-resolution in the feedback-mail as well. As I understand, the necessary javascript must already have been executed on the client, when the server runs the php-script with the mail-function. So do I need to send the js-variables containing the resolution-values from each page, which may direct to the mail-script? Could I get the resolution on index.htm an store it for later use, perhaps by passing it in the URL? I never did that before so I don't know how to pass it with js and how to read the values with php. Okokok - you might say RTFM but this question seems to be too simple for mentioning it in a manual.
The script I'm working on is on
http://www.herrnaumann.de/wandkunst/fra ... t/mail.php
Thank You for any help
Alex
email-feedback including screen resolution
Moderators: egami, macek, gesf
- swirlee
- Moderator
- Posts: 2257
- Joined: Sat Jul 05, 2003 1:18 pm
- Location: A bunk in the back
- Contact:
My JavaScript is lousy, so I can't give you many specifics, but here's how I'd do it: On the page with the mail form, have a hidden form field, e.g.
Then, on the page, put JavaScript that detects the resultion when the page loads and sets the value of the hidden form field to the detected resolution. Then, when the form is submitted, you can just add the contents of the field (e.g. $_POST['resolution']) to your e-mail message.
I hope that's helpful. You'll have to come up with the actual JavaScript on your own, unless someone else wants to provide it.
Code: Select all
<input type="hidden" name="resolution" value="">
Then, on the page, put JavaScript that detects the resultion when the page loads and sets the value of the hidden form field to the detected resolution. Then, when the form is submitted, you can just add the contents of the field (e.g. $_POST['resolution']) to your e-mail message.
I hope that's helpful. You'll have to come up with the actual JavaScript on your own, unless someone else wants to provide it.
-
- New php-forum User
- Posts: 32
- Joined: Tue Jul 30, 2002 11:27 pm
It doesn't work. What I did in the <head> of this mail.php:
<script language="JavaScript">
var hoehe, breite, farbe, aufloesung;
high = screen.height;
wide = screen.width;
col = screen.colorDepth;
var resolution = wide + "x" + high + "Color:" + col;
</script>
In the form (action="mail.php"):
<input type="hidden" name="resolution" value="">
$res = $_POST['resolution'];
and in the html-body of the email I called $res. Nothing.Empty.
I don't know whether it's a simple script mistake or a basic misunderstanding of how php and javascript are executed. I thought, the javascript is run, when the page is loaded for the first time. The POST of the formular calls the same php-code again with the variables' values set in the form. Now where is the value of the hidden 'resolution' field...gone...Nirvana?
Help
Alex
<script language="JavaScript">
var hoehe, breite, farbe, aufloesung;
high = screen.height;
wide = screen.width;
col = screen.colorDepth;
var resolution = wide + "x" + high + "Color:" + col;
</script>
In the form (action="mail.php"):
<input type="hidden" name="resolution" value="">
$res = $_POST['resolution'];
and in the html-body of the email I called $res. Nothing.Empty.
I don't know whether it's a simple script mistake or a basic misunderstanding of how php and javascript are executed. I thought, the javascript is run, when the page is loaded for the first time. The POST of the formular calls the same php-code again with the variables' values set in the form. Now where is the value of the hidden 'resolution' field...gone...Nirvana?
Help
Alex
-
- New php-forum User
- Posts: 32
- Joined: Tue Jul 30, 2002 11:27 pm
of course I wrote:
var high, wide, col, resolution;
var high, wide, col, resolution;
- swirlee
- Moderator
- Posts: 2257
- Joined: Sat Jul 05, 2003 1:18 pm
- Location: A bunk in the back
- Contact:
At some point you actually have to assign the value to the hidden form field. I'm not sure exactly, but once you have the visitor's resolution in the JavaScript variable "resolution", you should be able to put it into the form field like so:
Now don't just copy my code verbatim, because, as I said, my JavaScript is crap. I'm sure someone else around here can tell you if the above will work.
Code: Select all
<input type="hidden" name="resolution" value="<script language="JavaScript">document.write(resolution)</script>">
Now don't just copy my code verbatim, because, as I said, my JavaScript is crap. I'm sure someone else around here can tell you if the above will work.
-
- New php-forum User
- Posts: 32
- Joined: Tue Jul 30, 2002 11:27 pm
Thank you so far...it's late. Try again tomorrow.
Alex
Alex
- ruturajv
- php-forum Super User
- Posts: 1279
- Joined: Sat Mar 22, 2003 9:42 am
- Location: Mumbai, India
- Contact:
here is an ans.
now the php page where this info is posted
Code: Select all
<script language="JavaScript">
var hoehe, breite, farbe, aufloesung;
high = screen.height;
wide = screen.width;
col = screen.colorDepth;
var resolution = wide + "x" + high + "Color:" + col;
</script>
<input type='hidden' name=resolution value="document.write(resolution);">
now the php page where this info is posted
Code: Select all
<?php
//get the variable
//make sure the variable is posted via POST if passed via
// ur use $_GET['resolution']
$resolution = $_POST['resolution']
//use this variable using the mail fn.
mail(all the necessary info);
?>
-
- New php-forum User
- Posts: 32
- Joined: Tue Jul 30, 2002 11:27 pm
Here was my mistake!
I thought the js could run in the <head> and that's ok. But I had to place it somewhere in the form or below !!!
Yippieh...it works
Thanks a lot
Have a nice weekend..as I will have it
Alex
I thought the js could run in the <head> and that's ok. But I had to place it somewhere in the form or below !!!
Yippieh...it works
Thanks a lot
Have a nice weekend..as I will have it
Alex