javacious Posted June 6, 2008 Share Posted June 6, 2008 Hello all, first time poster! I'm having some difficulties with creating a form for a website. The idea here is I have a variable called $ip that I've stuck the form-posters IP address into. I am now trying to stick that same variable as a value into a hidden input field... So how do I insert a variable INSIDE of a here doc? Example: <?php print<<<_FORM <input name="ipaddy" type="hidden" value="<?php echo $ip ?>"/> <textarea cols="40" rows="7" name="message"></textarea> <input name="submit" type="submit" value="Click to Send"/> _FORM; ?> The above example doesn't work.... the area in red needs help. Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/ Share on other sites More sharing options...
chaking Posted June 6, 2008 Share Posted June 6, 2008 I haven't used it, but doesn't <<< act as an echo already? I could be way off... try value='$ip' /> Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558844 Share on other sites More sharing options...
chaking Posted June 6, 2008 Share Posted June 6, 2008 This should work though if the above doesn't: echo "<form method=' ' action=' ' >\n <input name='ipaddy' type='hidden' value='$ip' />\n <textarea cols='40' rows='7' name='message'></textarea>\n <input name='submit' type='submit' value='Click to Send'/>"; Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558845 Share on other sites More sharing options...
DarkWater Posted June 6, 2008 Share Posted June 6, 2008 <?php print <<<_FORM <input name="ipaddy" type="hidden" value="$ip"/> <textarea cols="40" rows="7" name="message"></textarea> <input name="submit" type="submit" value="Click to Send"/> _FORM; ?> Don't use chaking's last way. HTML tags should have " " around their values, not ' '. Some browsers don't like it. Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558846 Share on other sites More sharing options...
javacious Posted June 6, 2008 Author Share Posted June 6, 2008 I haven't used it, but doesn't <<< act as an echo already? I could be way off... try value='$ip' /> Unfortunately, I've already tried that and it didn't work. Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558847 Share on other sites More sharing options...
awpti Posted June 6, 2008 Share Posted June 6, 2008 This is the correct way: <?php $variable = "I'm a variable. Howdy!"; echo <<<HTML This is some text. The following is a variable: $variable Enjoy. HTML; ?> [17:39] [root@geeklan : ~]# php heredoc.php This is some text. The following is a variable: I'm a variable. Howdy! Enjoy. Another example (extended): <?php $variable = "I'm a variable. Howdy!"; echo <<<HTML This is some text. The following is a variable: $variable Enjoy. HTML; $variable2 = <<<VAR I'm text in a variable assigned using HEREDOC! Wow! And I'm the original variable: $variable VAR; echo $variable2; ?> Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558848 Share on other sites More sharing options...
javacious Posted June 6, 2008 Author Share Posted June 6, 2008 Thanks a ton Darkwater and Awpti... I believe I finally got it working... Wow, you guys were quick - I really appreciate it! Solved. Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558850 Share on other sites More sharing options...
Lodius2000 Posted June 6, 2008 Share Posted June 6, 2008 one more idea, sorry im late to the party, make your form tag read <form method="post" action="'.$_SERVER['PHP_SELF'].'"> and the value="ip" should become a key in the array $_POST accessed by $_POST['ip'] $_SERVER has many different array keys, dont remember them all but that is how I process my forms new to php but makes sense to me Link to comment https://forums.phpfreaks.com/topic/108927-solved-how-do-i-use-variables-inside-of-a-here-doc/#findComment-558910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.