I have the following code in my form:
<form action="mail.php" method="POST">
Is there a way to add another submit button and let php know that if button1 is used it sends the data to mail.php while is button two is used it send the data to mail2.php ?
Thanks for the help
It would be correct to use the value of the radio-button, passing the parameter option, like:
<input type="radio" name="how" value="mail1" id="radio1"><label for="radio1">Name of parameter1</label>
<input type="radio" name="how" value="mail2" id="radio2"><label for="radio2">Name of parameter2</label>
and on the server:
$mail = $_POST['how']==mail1?'mail1':'mail2';
include($mail.'.php');
Related
I am writing a search box in HTML that takes the user input and append it to the URL as a parameter. The code of the form looks like this.
<form name="form" action="" method="get">
<input type="text" name="id" id="idresponse">
<input type="submit" value="Submit">
</form>
This will bring the user from example.com/test.html to example.com/test.html?id=12345678 assuming they entered 12345678 at the text box.
However, if the user inputted nothing and clicked Submit, they will be brought to example.com/test.html?id=, which I don't want. How can I modify the code so that the form knows that a certain field is left blank and do not send the parameter with the URL? In this case, the desired URL would be example.com/test.html.
edit 20210405 2057 changed the id of the input from idresposne to idresponse to avoid confusion
The so-called URL parameters is the querystring of the URL.
The following code does not use jQuery, but achieves a similar effect. (written by RobG)
<form name="form" onsubmit="disableEmptyInputs(this)" action="" method="get">
<input type="text" name="id" id="idresponse">
<input type="submit" value="Submit">
</form>
<script>
function disableEmptyInputs(form) {
var controls = form.elements;
for (var i=0, iLen=controls.length; i<iLen; i++) {
if (controls[i].value == '') controls[i].disabled = true;
}
}
<script>
This will remove all the parameters but the ? will still trail the URL. i.e. the URL will be example.com/test.html? instead. However, this does not matter because they both point to the same address.
Refer to these links (kindly provided by Progman) for other ways of doing this, including using jQuery.
Delete empty values from form's params before submitting it
Delete empty values from form's params before submitting it
How can I remove empty fields from my form in the querystring?
Thanks.
I have this code:
<?
$page = $_GET['page'];
$find = $_GET['find'];
?>
<form method="post" action="#">
<input type="text" name="whatever" value="1">
<button class="btn btn-default" type="submit">Post this</button>
</form>
My initial URL is:
htttp://www.someplace.com?page=1&find=lookfor
When sending the post form I am getting back "page" and "find" vars along the "whatever" input value. Why? Is this happening because my form action is "#"?
By the way, this is what I want, this saves me the work of posting hidden input values. But I want to be sure it is valid.
Using action="#", you will submit the form to the current URL. Your GET vars are part of this URL so that is why you're getting them again.
More infos on this question.
<input id="isChecked" name="isChecked"
type="checkbox"></input><input name="_isChecked"
type="hidden" value="on"></input> <label for="isChecked">Checked</label>
I have this checkbox on the top of my *.html.
I want to use the value of "isChecked" input in a "form" like seting 1/0 (true/false) to a hidden input:
<form id="someForm" class="form xml-display form-inline"
th:action="#{/doSomething}" method="post">
.....
<input type="hidden" name="isChecked"
th:value="GET VALUE FROM THE GLOBAL CHECKBOX" />
.....
</form>
So can I do this without any JS?
Should I add an object in my java controller to the Model so I can set the value from the "isChecked" checkbox to it and then use the object in th:value="${objectFromJavaController}" for the hidden input ? I tried setting a th:object="${objectFromJavaController}" for the checkbox and then passing it to the hidden input but it didn't work (th:value = ${"objectFromJavaController"}) ?
So can someone help me ? Thanks in advance!
Surely somethin like this is simple enough?
<input id="newsletter" name="newsletter" type="checkbox" checked="yes" value="yes"/>
This brings back the same result. anything else would be no. (with PHP code telling them apart)
I have check box at UI side on which i want to bind data coming from web service in form of jason
Html code:
<label class="checkbox-inline nopaddingleft" for="radio1">
<input name="radio1" type="checkbox" id="radio1"
class="checkbox-inline margin-right-five"
value="name" checked={{insuredProfile.isScrubbed}} />Scrub
</label>
The value i want to bind is:{{insuredProfile.isScrubbed}} it will be true or false
Thanks in advance
In your view use ngChecked.
In your controller you'll need to have something like:
$scope.insuredProfile = { isScrubbed: true };
You have to use ng-model for the checkbox input.
ng-model="insuredProfile.isScrubbed"
I am creating a web application where I want to pass the selection done by radio button to controller.Now,I want this action to be performed without submit button.I googled a lot but did'nt get the way to do this without submit button.
here is the HTML Code for this requirement
<form action="${pageContext.request.contextPath}/env" method="post">
QA71<input type="radio" name="env" value="QA71" checked="checked">
QA72<input type="radio" name="env" value="QA72" >
</form>
Here is the code of java for this requirement
#RequestMapping(value = "/env", method = RequestMethod.POST)
public String env(HttpServletRequest request){
logger.info("parameter is "+request.getParameter("env"));
return "home";
}
I appreciate your help.
If you don't want to use a submit button you should use javascript to submit the form one way to do that is:
document.getElementById("myForm").submit();
so first you need to put an id attribute to your form, and second you need to decide in what event you want to submit the form in this example I chose on blur of the second radio:
<form id="myForm" action="${pageContext.request.contextPath}/env" method="post">
QA71<input type="radio" name="env" value="QA71" checked="checked">
QA72<input type="radio" name="env" value="QA72" onBlur="submitForm()">
</form>
function submitForm() {
document.getElementById("myForm").submit();
}