Page 1 of 1
Calling a variable inside a form inside an echo statement??
Posted: Wed Jan 07, 2004 4:30 pm
by tdelobe
Using PHP 4 does anyone know how I can make the domain a variable in this form code that is inside of an echo statement?
I want
http://www.test.com/ (see code below) to be a variable strored in lets say:
$domain
However I am having trouble using a vairable ($domain) inside the form tag when it is embedded in an echo statement. Anyone?
Code: Select all
<?php
echo "<FORM ACTION="http://www.test.com/process.php" METHOD="POST">";
?>
Posted: Wed Jan 07, 2004 4:39 pm
by basdog22
I think you must escape the "//"'s like "\/\/"

Posted: Wed Jan 07, 2004 4:41 pm
by JAM
Another idea is to use single quotes;
Code: Select all
echo '<FORM ACTION="http://www.test.com/process.php" METHOD="POST">';
Posted: Wed Jan 07, 2004 4:41 pm
by Sevengraff
you should be able to get the domain name by using $_SERVER['HTTP_HOST'].
When printing variables with echo, I like to use single quotes like this:
Code: Select all
echo '<form action="' . $_SERVER['HTTP_HOST'] . ' ... other html ';
a little more clarification
Posted: Thu Jan 08, 2004 9:13 am
by tdelobe
Ok, so I was trying to simply my original request a little so not to provide too much unneccessary info but I dont think either of those way work for my purposes. Here is my exact code....
So you will notice I have an encoded url that I need to send to jangomail. The domain I want to have as a variable is this the bolded part
after return_address=. Instead of
having http%3A%2F%2Fdev%2Eusta%2Eorg%2F in there I wanted to put a variable like say:
$domain
so it would look like this:
return_address=
$domainforms%2Ephp%3Furh%3Dhome%2Emarketplace%2Emailing%5Flist%2Ethankyou%5Fmailing
Is this possible inside the form action which is inside the echo?
Code: Select all
<?php
echo "<FORM ACTION="http://www.jangomail.com/processcode.asp?emailcat_id=295419&return_address=[b]http%3A%2F%2Fdev%2Eusta%2Eorg%2F[/b]forms%2Ephp%3Furh%3Dhome%2Emarketplace%2Emailing%5Flist%2Ethankyou%5Fmailing&send_email=ssullivan%40usta%2Eorg" METHOD="POST" NAME="J295419" ID="J295419" onSubmit="if ((email.value=='') || (first_name.value=='') || (last_name.value=='')) {alert('Please fill in all required fields'); event.returnValue=false; return false;}">";}
?>
Posted: Thu Jan 08, 2004 12:58 pm
by Gen-ik
So you're trying to put a variable into an echo() statement?
Code: Select all
<?php
$domain = "http://somewhere.com";
echo '<form action="{$domain}" method="post">';
?>
perfect
Posted: Thu Jan 08, 2004 1:20 pm
by tdelobe
This is exactly what I was looking for. I was not aware you could use {} like that. This works perfect. Thanks!
Posted: Thu Jan 08, 2004 1:26 pm
by Gen-ik
Well I aim to please... but normally miss
