473,554 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submit form with variable for action?

Hi everyone,

So, i've got a form that is very simple. It hold three elements:
username, password, and domain. The goal here is to have the form
submit the login to an administrative section depending on which domain
someone has chosen.

For instance, let's say we have three administrative sites, that all
have different URLs, but we want this one form to handle logging into
any of them. So, the form itself needs to have a dynamic action
element.

Here's an example:

Code:

<form action="http://www.mysite.com/admin/index.php" method="post"
name="login" id="login" >
<input name="usrname" type="text">
<input name="pass" type="password" >
<input name="domain" type="text">
<input name="submit" type="submit" value="Login">
</form>

Now, the issue is, instead of the action I have now, I need the action
to change based on what is typed by the user in the domain field. So in
the case above, if the user types "bobsite.co m" in the domain field,
the action needs to point to "http://www.bobsite.com/admin/index.php".

I have looked near and far for a solution for this. Using PHP, so have
some flexibility, and javascript is okay if we have to use it.

Best,
Ryan

Sep 25 '05 #1
6 13369
tencip wrote:
<form action="http://www.mysite.com/admin/index.php" method="post"
name="login" id="login" >
<input name="usrname" type="text">
<input name="pass" type="password" >
<input name="domain" type="text">
<input name="submit" type="submit" value="Login">
</form>

Now, the issue is, instead of the action I have now, I need the action
to change based on what is typed by the user in the domain field.


Is method="post" set in stone?

If not, the easy solution is this:

<form action="somefil e.php" method="get">
<input name="usrname">
<input name="pass" type="password" >
<input name="domain">
<input type="submit" value="Login">
</form>

The form will *always* submit to "somefile.p hp", but then from
somefile.php we redirect to the correct location:

<?php
$url = sprintf("http://%s/admin/index.php?usrna me=%s&pass=%s",
$_REQUEST['domain'], $_REQUEST['usrname'], $_REQUEST['pass']);
header("Locatio n: $url");
?>
<title>Redirect </title>
<h1>Redirect</h1>
<p><a href="<?=$url?> "><?=$url?> </a></p>

Of course, if you use GET rather than POST you have the problem of the
password being part of the URL, in plain sight.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Sep 25 '05 #2
> Is method="post" set in stone?

Unfortunately, yes, it's set in stone. So while your example would
have worked great if this were a GET, it's a POST. =(

Any other ideas?

Sep 25 '05 #3
tencip wrote:
Hi everyone,

So, i've got a form that is very simple. It hold three elements:
username, password, and domain. The goal here is to have the form
submit the login to an administrative section depending on which domain
someone has chosen.


Ok, this is an ugly hack that uses javascript. I would never use it
because there is no guarantee javascript is enabled.

<html>
<body>
<? if (!is_null($_POS T['domain'])) { ?>
<form name='second' method='POST' action='<? $_POST['domain'];
?>/test/test2.php'>
<input type='hidden' name='name' value='<? print $_POST['name']; ?>'>
<input type='hidden' name='password' value='<? print
$_POST['password']; ?>'>
<input type='submit'>
</form>
<script language="javas cript">document .forms[0].submit()</script>
<? } else { ?>
<form method='POST'>
domain: <input type='text' name='domain'>< br>
Name: <input type='text' name='name'><br >
Password: <input type='text' name='password' ><br>
<input type='submit'>
</form>
<? } ?>
</body>
</html>
Sep 26 '05 #4
tencip wrote:
Hi everyone,

So, i've got a form that is very simple. It hold three elements:
username, password, and domain. The goal here is to have the form
submit the login to an administrative section depending on which domain
someone has chosen.

For instance, let's say we have three administrative sites, that all
have different URLs, but we want this one form to handle logging into
any of them. So, the form itself needs to have a dynamic action
element.

Here's an example:

Code:

<form action="http://www.mysite.com/admin/index.php" method="post"
name="login" id="login" >
<input name="usrname" type="text">
<input name="pass" type="password" >
<input name="domain" type="text">
<input name="submit" type="submit" value="Login">
</form>

Now, the issue is, instead of the action I have now, I need the action
to change based on what is typed by the user in the domain field. So in
the case above, if the user types "bobsite.co m" in the domain field,
the action needs to point to "http://www.bobsite.com/admin/index.php".

I have looked near and far for a solution for this. Using PHP, so have
some flexibility, and javascript is okay if we have to use it.

It's quite simple in JavaScript.

First, remove the action from the form definition
<form method="post" name="login" id="login" >

Then, instead of using type=submit, use type=button.
<input type=button name=submit value="Login"
Onclick="Submit Form(this.form) ;">

function SubmitForm(form )
{
if (form.domain.va lue == "xxx")
form.action = "xxx"
else
form.action = "zzz";

form.submit(); // Submit the page
return true;
}

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*************** **************
Sep 26 '05 #5
This works on my computer, should work on yours as well:
just type yahoo.com in the third field:
<html>
<head>
<title>Variab le action field</title>
</head>
<body>
<form action="varacti on.php" method="post" name="login" id="login">
Username:<input name="usrname" type="text"/>
Password:<input name="pass" type="password"/>
Domain: http://www.<input name="domain" type="text"/>
<input name="submit" type="submit" value="Login"/>
</form>
<?php
if (isset($_POST['submit'])){
header("Locatio n: http://www.{$_POST['domain']}");
}
?>
</body>
</html>

Sep 27 '05 #6
Joseph S. wrote:
header("Locatio n: http://www.{$_POST['domain']}");


In the absence of a different status code, that will send a 302 (temporary
redirect). But the HTTP1.1 spec warns that some browsers treat 302
responses as if they were 303s, meaning that they issue a GET request no
matter what the first method was, be it HEAD, POST, whatever. Any
information POSTed the first time around wouldn't be sent again.

Your solution suggests that not all browsers treat 302s like that, that
some stick with POST.

To disambiguate this, in theory at least, HTTP1.1 provides the 303 and 307
status codes. 303 is for when user agents should perform a GET on the
Location URI, 307 for when they should continue using the same method as
before (possibly involving user interaction). Some browsers don't grok
these though. More details at

http://www.ietf.org/rfc/rfc2616

--
Jock
Sep 30 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7779
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM: The form won't submit if the link is clicked, but will submit if the SUBMIT button is clicked. I need to call a function to change the form's action...
1
1308
by: kjex | last post by:
I'm rewriting a webshop where all the "ugly submitbuttons" are changed with more complexed and nice looking <a href="#" onclick="">'s So here is the case, in the form there are several submitbuttons that makes the backend javaengine deside what do do; <input type=submit name="More<%= question.getAttributeKey().toString() %>"...
1
1611
by: charlie fortune | last post by:
I want to use a form with several different possibilities of posting to a single PHP program. Is there a way of telling the action not just the name of the file, but which function to call with the information ?
5
8425
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform' action='ins_op.php' method='post'>"; lots of form stuff
5
5889
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse button to open the "file browse" dialog and the Submit button to submit the form data.
5
17685
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input type=password maxlength="8" name="password" value="`pss`"> where usr and pss are sent from the previous form.
10
6060
by: ljlolel | last post by:
So.. I have a form that submits to an ASP.net site made in C-sharp. The ASP site is not mine, i do not have the server side code. When I submit from my form by pressing the Submit button, I get different results than when I use a javascript submit: form1.submit();. I think the javascript submit is working as it should, since I want the...
13
69984
by: deko | last post by:
I have a basic feedback form with a submit button. After the "send" button is clicked, I want the user to be redirected to a different page that says "Your message has been sent." How do I do this? I've tried using: header("Location:http://www.mysite.com/send-confirm.php");
11
5276
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. How do I submit that form1 from the javascript from my current window? Thanks.
0
7579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6120
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5414
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5136
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3539
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1112
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.