waverider Posted July 17, 2006 Share Posted July 17, 2006 Hello,I am trying to pass a variable from a PHP page containing an HTML form, using a hidden field, to another PHP page which then sends an Email comtaining the data passed. All other fields are passed OK, retrieved using the structure [quote]$item = $_REQUEST["description"];[/quote] and sent successfully in the Email.However the hidden field doesn't pass the value of the variable successfully.The hidden field structure is as below:[quote] <input type="hidden" name="description" value="$description">[/quote]The variable $description exists, but of course what is passed to the next page is '$description' rather than it's value. How do I pass the value of the variable rather than it's name to the next page? I have tried passing it in the url through:[quote]<form method="post" action="http://www.mywebsite.com/mowers_query_mail.php?description=$description">[/quote]but this doesn't appear to work either.Any thoughts?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/ Share on other sites More sharing options...
willfitch Posted July 17, 2006 Share Posted July 17, 2006 My first guess would to first ensure that the description hidden field is within the <form> </form> tags. If it is, try using $_POST['description'] rather than REQUEST. It's safer. Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59149 Share on other sites More sharing options...
waverider Posted July 17, 2006 Author Share Posted July 17, 2006 [quote author=willfitch link=topic=100835.msg398395#msg398395 date=1153108285]My first guess would to first ensure that the description hidden field is within the <form> </form> tags. If it is, try using $_POST['description'] rather than REQUEST. It's safer.[/quote]Thanks for the replyYes it is within the form tags. Thanks for the suggestion re: $_POST and security, however making this change won't resolve the problem of passing the variable value will it? Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59152 Share on other sites More sharing options...
willfitch Posted July 17, 2006 Share Posted July 17, 2006 It could.$_REQUEST works the same way as register_globals. Remember the letters GPCS. 1. GET2. POST3. COOKIE4. SESSIONThat is the order PHP will look for that variable. Post some of the code you use to handle the form. Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59153 Share on other sites More sharing options...
waverider Posted July 17, 2006 Author Share Posted July 17, 2006 Thanks again for the help,Code I am using to retrieve and send the Email is as follows ( I have left out all the error checking and security stuff as I have tried everything with this commented out and still get the same result) - I have also changed to POST as you suggested and everything but the one variable works with that:[quote]<?php$to = "my@emailaddress.com";$subject = $_POST["realname5"];$item = $_POST["description"];$body = $_POST["postal5"];$email = $_POST["email"];$name = $_POST["realname5"];$phone = $_POST["phone5"];$headers = "From: $email";mail($to, $subject, "Name: $name\nEmail: $email\nTelephone: $phone\nItem of Interest: $item\nMessage: $body", $headers);header( "Location: http://www.mywebsite/thankyou.htm" );?>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59164 Share on other sites More sharing options...
willfitch Posted July 17, 2006 Share Posted July 17, 2006 Ok.If everything else is being received, then you need to consider looking at the simple things. Go through the following steps:1. Ensure the hidden field "description" is within the <form> tags </form>2. Ensure the spelling of the "description" field is spelled correctly. (i.e. <input type="hidden" name="description"> and $_POST['description'] match)3. Do a var_dump($_POST) to see everything that is being sent. Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59166 Share on other sites More sharing options...
kenrbnsn Posted July 17, 2006 Share Posted July 17, 2006 The problem is with this line:[code]<input type="hidden" name="description" value="$description">[/code]As far as I can tell from this one line taken out of context, it is a pure HTML line and the value of the field will be literaly [b][color=red]$description[/color][/b].If you want to pass the value of the variable [b]$description[/b], then use this line instead:[code]<input type="hidden" name="description" value="<?php echo $description; ?>">[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59175 Share on other sites More sharing options...
waverider Posted July 17, 2006 Author Share Posted July 17, 2006 [quote]If you want to pass the value of the variable $description, then use this line instead:Code:<input type="hidden" name="description" value="<?php echo $description; ?>">[/quote]Thanks Ken - that's exactly what I wanted - I thought that's where the problem was but wasn't sure how to resolve it - fixed now :-) Quote Link to comment https://forums.phpfreaks.com/topic/14810-passing-variable-to-mail/#findComment-59182 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.