Replace this by only one form - html

how can I replace this code, by only one Form please.
<form method="post" action="<c:url value="/deconnexion" />"><input type="submit" value="Déconnexion" class="deco" /></form>
<form method="post" action="<c:url value="/accueil" />"><input type="submit" value="Retour" class="deco" /></form>

What you want to do is impossible, each form will submit it's information to a single location, which is your action property in your form.
What you can do, alternatively, is manage two different cases in the same form. Your form would look like that :
<form method="post" action="<c:url value="/redirection" />">
<input id="deco" type="submit" value="Déconnexion" class="deco" />
<input id="retour" type="submit" value="Retour" class="deco" />
<input id="type" name="type" type="hidden" value="" />
</form>
You would need Javascript (Jquery) code to assign the type of redirection in the hidden field before the form is submitted :
<script type="text/javascript">
$('#deco').click(function(event)
{
$('#type').val("Déconnexion");
});
$('#retour').click(function(event)
{
$('#type').val("Retour");
});
</script>
Then, in the PHP, you would redirect to the page or function you wish with this condition :
if ($_POST["type"] == "Déconnexion")
// Do something
else if ($_POST["type"] == "Retour"
// Do something else

Related

How would I post an html form but, still redirect to a thank you page after the form has posted? [duplicate]

This is my form code:
<form enctype="multipart/form-data" name="upload-file" method="post" action="http://example.com/upload">
<div class="formi">
<input id="text-link-input" type="text" name="url" class="link_form" value="your link" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
<input type="submit" value="OK" class="link_but" />
</div>
<div class="upl" title="Upload"><img src="http://example.com/example.png" alt="" style="vertical-align:middle;"/>Upload
<input type="file" name="file" size="1" class="up" onchange = "document.getElementById('text-link-input').value = String(this.value).replace('C:\\fakepath\\','')"/>
</div>
</form>
Now, I want to redirect the submitter to any page of my choice after the form data has been submitted, but the action resides on another website where I cannot edit. Is it possible to redirect the user to any page after he has submitted the data to that site?
From some Googling, this is what I have found. Adding this to form code:
onSubmit=window.location='http://google.com'
This didnt work. Maybe I didnt implement it correctly? This is what I did:
<form enctype="multipart/form-data" name="upload-file" method="post" onSubmit=window.location='http://google.com' action="http://example.com/upload">
Another person says adding a hidden field should work:
<input type="hidden" name="redirect" value="http://your.host/to/file.html">
How should I implement this is my code?
Suggestions and help awaited...
Try this Javascript (jquery) code. Its an ajax request to an external URL. Use the callback function to fire any code:
<script type="text/javascript">
$(function() {
$('form').submit(function(){
$.post('http://example.com/upload', function() {
window.location = 'http://google.com';
});
return false;
});
});
</script>

How to see if input contain some value?

I've some form like this:
<form action="#" method="post">
<input type="text" name="website" />
</form>
How I can find if user enter website with http:// or without? I want to show it in:
<a href="value from input">
Any suggestions how to validate this form and send it to database as right link like: http://website...?
You may use javascript to validate input.
function validate()
{
var input = document.getElementsByName("website")[0].value;
if(input.startsWith("http://")) {
alert("valid input");
return true;
}
alert("invalid input");
return false;
}
<form action="#" method="post" onsubmit="return validate()">
<input type="text" name="website" />
<input type="submit" />
</form>

add parameters to form url before submit

I need to add a path to a file to the form url before submitting. I created therefore a text field and want to add the text to the url without php.
can somebody help?
the existing code:
<form action="http://127.0.0.1:8080/WebService1/HTTPMethod_1?new_value=value" method="post">
<input type="text" value="" size="30" name="filename">
<input type="submit" name="submit" value="Submit" class="continue-button">
</form>
look into using hidden input fields. these allow you to send form data, but not necessarily show a form field.
for instance:
<script type="text/javascript">
function setFormAction() {
document.myForm.action = document.getElementById("url").value;
}
</script>
<form name="myForm" method="POST" action="default.php">
<input type="value" name="url" id="url" />
<input type="submit" name="submit" onclick="setFormAction();" />
</form>

passing input text to action field

I want to pass the input field to the form action part covering field; so it looks like /{user}/some_integer_in_field if you know what I mean.
<form action="<c:url value='${user}/?field'/>"
method="post" >
<input type="hidden" name="_method" value="DELETE">
<input type="text" name="field" id="field"/>
<input type="submit" value="DELETE">
</form>
can someone help? is this possible?
I see you've only tagged HTML. What other languages are you using? I recommend you change the desired action via JavaScript, based on the user variable.
HTML
<form>
<input type="hidden" name="_method" value="DELETE">
<input type="text" name="field" id="field"/>
<input type="submit" value="DELETE" id="submitBtn">
</form>
JavaScript
<script>
var sub = document.getElementById('submitBtn');
// When sub is clicked, compare user var
sub.addEventListener('click', function(event){
if(user == 1){
// Perform post action 1
}else if(user == 2){
// Perform post action 2
}
// etc...
});
</script>
You'll have to change the user variable as the field changes as well.

HTML Form Redirect After Submit

This is my form code:
<form enctype="multipart/form-data" name="upload-file" method="post" action="http://example.com/upload">
<div class="formi">
<input id="text-link-input" type="text" name="url" class="link_form" value="your link" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
<input type="submit" value="OK" class="link_but" />
</div>
<div class="upl" title="Upload"><img src="http://example.com/example.png" alt="" style="vertical-align:middle;"/>Upload
<input type="file" name="file" size="1" class="up" onchange = "document.getElementById('text-link-input').value = String(this.value).replace('C:\\fakepath\\','')"/>
</div>
</form>
Now, I want to redirect the submitter to any page of my choice after the form data has been submitted, but the action resides on another website where I cannot edit. Is it possible to redirect the user to any page after he has submitted the data to that site?
From some Googling, this is what I have found. Adding this to form code:
onSubmit=window.location='http://google.com'
This didnt work. Maybe I didnt implement it correctly? This is what I did:
<form enctype="multipart/form-data" name="upload-file" method="post" onSubmit=window.location='http://google.com' action="http://example.com/upload">
Another person says adding a hidden field should work:
<input type="hidden" name="redirect" value="http://your.host/to/file.html">
How should I implement this is my code?
Suggestions and help awaited...
Try this Javascript (jquery) code. Its an ajax request to an external URL. Use the callback function to fire any code:
<script type="text/javascript">
$(function() {
$('form').submit(function(){
$.post('http://example.com/upload', function() {
window.location = 'http://google.com';
});
return false;
});
});
</script>