Click to See Complete Forum and Search --> : feedback mail with screen-resolution
DonMArtin
08-28-2003, 02:25 PM
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 and 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/frames/kontakt/mail.php
Thank You for any help
Alex
AdamGundry
08-28-2003, 04:15 PM
You could do something like this on the form page:
<input type="hidden" name="resolution" value="unknown">
<script type="text/javascript">
document.formname.resolution.value = screen.width + ' by ' + screen.height;
</script>
Adam
DonMArtin
08-28-2003, 04:47 PM
In the html-body of the email I called $resolution. 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 think, 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
Da Warriah
08-28-2003, 07:09 PM
the resolution should be sent along with the rest of the form...so you should be able to access it using $_POST['resolution'], which should give you something like "800 by 600"
AdamGundry
08-29-2003, 04:28 AM
Yes, on the PHP side you need to use $_POST['resolution'] unless the directive register_globals is on (off by default in newer versions of PHP). See http://www.php.net/variables.external
On the JS side, did you change "formname" to the actual name of your form, which (from looking at your page) appears to be "nachricht"?
Adam
DonMArtin
08-29-2003, 05:08 AM
Yes, I replaced formname with nachricht
Yes, globals are on as I use them in a php-function and they work. Maybe there's my problem. The script not only validates the form but also does it show the already entered values in each other field if one is not valid. With $_POST['field'] I read the values and echo them again as values. That works. What is to be done with hidden fields. Do I have to include them in the validation function. The function's code:
<?php
function show_form($name="",$mailadresse="",$message="",$headline="")
{
?>
<form>
...
</form>
}
(validation if-else) formname
DonMArtin
08-29-2003, 05:14 AM
if
(empty($name) || empty($mailadresse) || empty($message))
{
show_form($_POST['name'],$_POST['mailadresse'],$_POST['message'],$headline='something s missing');
}
DonMArtin
08-29-2003, 05:19 AM
I'm sorry for any mistyping - now I changed the keyboard's batteries
AdamGundry
08-29-2003, 05:24 AM
Yes, I you will need to add the resolution JS code where you put the ellipsis (...) in that code. Alternatively, write the hidden field out with the previously posted value as default using PHP.
Adam
DonMArtin
08-29-2003, 06:31 AM
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
JavaScript can run in the head, you just need to run it after the page is done loading (if you want to fill out a form field) via onload. The reason for this, is that until the page has finished loading, the JavaScript will have no way of knowing that the form field it is supposed to be filling out exists.