Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php form issue

Status
Not open for further replies.

IDTstudios1

Programmer
Aug 8, 2004
72
US
I have this simple form right? well, i need the "action" to be whatever is entered into the 'domain' field and then what you see on the form below. Ex. someone enters 'blah.com' in the domain field, then i need the form to post to blah.com/login.php

any help would be greatly appreciated,
Thanks

<form action="login.php" method="post">

<input type="Text" name="username" value="username" size="10">
<input type="Text" name="password" value="password" size="10">
<input type="Text" name="domain" value="domain.com" size="24">
<input type="submit" name="sumit">
 
This should work assuming that your HTTP_HOST is the domain name (it works for me):

Code:
<form action="<?= $_SERVER['HTTP_HOST'] ?>/login.php" method="POST">

If the login form is in the same PHP script as the one the form is going to POST to, then you might want to try this incase you decide to change the file's name for some reason:

Code:
<form action="<?= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ?>" method="POST">

Hope this helps.

---------------------------------------
 
I don't think that's what the OP wanted to do. I think he wants to submit the login information to the domain the user enters, a bad idea IMHO. You should give them a choice of valid domains and don't let anything else past your code.

Anyway, I don't believe you can do this with PHP alone using one form. Using two forms, it's possible.

If you want to use one form, you can use a little bit of Javascript to get it to go to "right" place.

In your login.php script, put this bit of Javascript between the '<head>' and '</head>' tags:
Code:
<script language="JavaScript">
function submitForm() {
document.login.submit();
}
</script>
In the '<body>' tag:
Code:
<body onLoad="javascript:submitForm()">
And in your main script:
Code:
echo '<form name=login method="POST" action=". $_POST['domain'] . "/script.php>'."\n";
echo '<input type=hidden name="username" value="' . $_POST['username'] . '">';
echo '<input type=hidden name="password" value="' .
$_POST['password'] . '">';
echo '</form>';
Note that you really should do some sanity checking before you create this form. Also, this won't work if Javascript is turned off.

Ken
 
If I am understanding you correctly, this is what I would do. As was stated above by kenrbnsn, using a text box and letting the individual decide what to insert is a bad idea (IMHO).

I would use an option pulldown. Use something like this near the begining of your script.
Code:
$domain = $_POST['domain'];
if(isset($domain)) {
echo "<html><head><meta http-equiv=\"refresh\" content=\"1; url=".$domain."\"></head><body>Taking you to ".$domain.".<br>Please wait ......</body></html>"; }
Then in the "body" part.
Code:
<FORM METHOD="POST" ACTION="login.php">
<select name="domain">
<option value = "domain1.com">domain1.com</option>
<option value = "domain2.com">domain2.com</option>
<option value = "domain3.com">domain3.com</option>
<option value = "domain4.com">domain4.com</option>
</select>

I hope this is of value to you in some way or another.
 
Thanks for all the help guys. Also, thanks for pointing out the user choosing domain issue. I had been trying to figure this out for two days and i guess i just overlooked the practical aspect of the script.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top