Calling a variable inside a form inside an echo statement??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tdelobe
Forum Commoner
Posts: 41
Joined: Thu Aug 07, 2003 2:28 pm
Location: washington, dc

Calling a variable inside a form inside an echo statement??

Post 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">";

?>
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

I think you must escape the "//"'s like "\/\/" :roll:
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Another idea is to use single quotes;

Code: Select all

echo '<FORM ACTION="http://www.test.com/process.php" METHOD="POST">';
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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 ';
tdelobe
Forum Commoner
Posts: 41
Joined: Thu Aug 07, 2003 2:28 pm
Location: washington, dc

a little more clarification

Post 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;}">";}

?>
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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">';

?>
tdelobe
Forum Commoner
Posts: 41
Joined: Thu Aug 07, 2003 2:28 pm
Location: washington, dc

perfect

Post by tdelobe »

This is exactly what I was looking for. I was not aware you could use {} like that. This works perfect. Thanks!
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Well I aim to please... but normally miss ;)
Post Reply