How to make multiple action in HTML form - html

Say I want to make double action in HTML form.
The first action would be to examle1.php
And the second action would be to example2.php
I have code like this
<form name="input" action="" method="post">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
So, how to insert the 2 actions above to the action=""?
Is it possible to do that?

No. You can have only one declared action attribute for the <form>
You can however, try:
Doing an AJAX POST for your first action and submitting the actual form on its success handler
Writing the server side script for your first action such that it redirects to your second action after it done.

In a form you can give only one action="action.php". But tell us why you want to have two actions ?

Related

Can a client(from browser) read/retrieve the file/script used in action attribute of html form?

I am trying to get the complete script that is used with post method in a form
Example:
<form method="post" name="abc" action="/dir/file">
...
...
...
<input type="hidden" name="xyz" value="AnyInt">
</form>
Could anyone please give me a hint, how this hidden parameter can be used to get the source code of the file in action attribute of html form?

HTML form that causes a GET request

Basic question. If I have a form in my HTML (where in my case someone inputs a date), how can I have my users cause a GET request with the contents of that form instead of a POST.
e.g. form entry (e.g date)... so 20190312
what I am trying to achieve is such that AFTER the user submits the form.. the user is the lead to page that has
GET domain.tld/scriptname.php?variable=20190312
and then the system then processes the GET request accordingly.
thank you
Maybe i'm missunderstanding what you are asking.
This can easly be achived using builtin GET method in FORM tag
<body>
<form id="form" method="GET" action="scriptname.php">
<input id="date-txt" type="text" name="date">
<input id="search-btn" type="submit" value="Submit">
</form>
</body>
While filling up above field ad clicking "Submit" form will be submitted and you can see in your url path/or/page/scriptname.php?date=INPUT_FIELD_VAL
for every input in #form with a name, if GET method is used, you'll see a ?name=value in the url
What you describe is the default behaviour of a form. If you don't want a POST request, then don't use a method attribute to set the request type to POST.
<form action="//domain.tld/scriptname.php">
<input name="variable" value="20190312">
<button>Submit</button>
</form>

One form inside another one form

I have one Form which have one submit button let us name this as FORM 1 and inside that form I have another form with one submit button and this form name is FORM 2. Now my problem is When i am clicking submit button of FORM 2, FORM 2 submit button is using an action of FORM 1 which i don't want. I know its sounds confusion but check the codes you will come to know :
<form action="pks.php" method="post">
<input type="text" name="mob">
<input type="text" name="opr">
<form action="pksa.php" method="post">
<input type="text" name="opra">
<input type="submit" value="SUBMIT">
</form>
<input type="submit" value="SUBMIT">
</form>
I am trying something like to achieve but i am not able to Please help me out
I have one Form which have one submit button let us name this as FORM
1 and inside that form I have another form with one submit button and
this form name is FORM 2.
In HTML you cannot nest <form> elements. This simply results in invalid markup and undefined behavior. You will have to reorganize your markup in a way that doesn't involve nested forms.
You cannot have nested forms. Browsers won't allow that. Actually if you inspect the form in browser developer tools, you will see that child forms are removed.

HTML Form Action: How to fetch text field & create a URL for Action (Method: POST)

I have a form like:
<form method="post" action="http://www.2-myWebSiteUri.com/file1.php" id="login">
<input type="text" name="TEXTBOX1"></input>
<input type="text" name="TEXTBOX2"></input>
<button type="submit" class="button" title="login" name="send" id="send2">Login</button></form>
I would like to perform custom "action=" in FORM using POST (method) however I am not getting how to perform it. Form action should be like, for example:
<form action="http://www.2-myWebSiteUri.com/TEXTBOX1/file1.php" method="post" id="login">
BUT form should collect the text value (TEXTBOX1) from the TEXTBOX1 which user will enter and same should be used as a input value in action URL as given above in the place of TEXTBOX1. Suppose in TEXTBOX1, I have written input value as "pasta" & submitted via button, then action url should be like:
<form action="http://www.2-myWebSiteUri.com/pasta/file1.php" method="post" id="login">
or if input value is noodles then action url should be like
<form action="http://www.2-myWebSiteUri.com/noodles/file1.php" method="post" id="login">
upon submission.
I've small authentication based scripts in different directories of domain
www.2-myWebSiteUri.com and I am trying to create a single form so that all can be logged in using a single form. User will just enter directory name "such as pasta and noodles as given in above example". This form will be hosted on another domain www.1-myWebSiteUri.com and when user wants to make login any of the scripts then he will open:
www.1-myWebSiteUri.com/login.php and this is the same login form for which I want to have custom actions.
Actually, I am trying to use directories as a category of games which host few online games. Categories will not be fixed and it will be added randomly, so i want to keep TEXTBOX instead of a Drop Down. We may halt few features in the game for different users. You can take this as a different directories with different games which can be accessed only via authentication. I just want to post all the credentials using a single form instead of 100 forms for each game and it will be very tough to share all these login links with users.
I have tested couple of codes including javascripts however none of them are working. I will be more then happy if any of you assist me in this regard.
No, that will not work.
You need a middle-ware script. Your description is lacking detail but this may help.
Change action destination to middle.php
<form method="post" action="http://www.2-myWebSiteUri.com/middle.php" id="login">
<input type="text" name="TEXTBOX1"></input>
<input type="text" name="TEXTBOX2"></input>
<button type="submit" class="button" title="login" name="send" id="send2">Login</button></form>
middle.php
Value of TEXTBOX1 is inserted into url as $txt1.
<?php
$txt1 = trim($_POST['TEXTBOX1']);
$txt2 = trim($_POST['TEXTBOX2']);
include("http://www.2-myWebSiteUri.com/$txt1/file1.php");
?>
Depending on values of TEXTBOX1 you may need to add urlencode:
$txt1 = urlencode(trim($_POST['TEXTBOX1']));

URL building for login

I am working on a Django project, in which a template login.html has code like -
<form name="input" action="welcome.html" method="get">
--------------SOME FORM ELEMENTS-----------------
<input type="submit" value="Login" />
</form>
When I click on Login, I want URL to be -
http://127.0.0.1:8000/welcome.html
or
http://127.0.0.1:8000/welcome.html?xxxxxxxxxxxxxxxxxx
but url comes out to be
http://127.0.0.1:8000/login.html/welcome.html?xxxxxxxxxxxxxxxxxx
(that is, "action" from form gets appended to the URL instead of getting appended to the domain) where "xxxxxxxx" stands for query submitted through form.
How can I achieve this?
<form name="input" action="/welcome.html" method="get">
You should set the action to be "/welcome.html".
thats really wired, try making your action="/welcome.html"