473,748 Members | 6,034 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 13394
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
7794
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 according to user's input before it is submitted.
1
1316
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() %>" value="<isa:translate key="marketing.jsp.ChangeFields"/>"> <input type=text name="SaveMktProfile"...
1
1619
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
8449
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
5902
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
17713
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
6089
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 server to process an __EVENTTARGET posting. When I click the submit button, it does not process the...
13
70005
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
5319
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
8991
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.