HTML form method post does not work with multiple submit - javascript

HTML form method post does not work with multiple submit
I have the following
<form id="myForm" method="post" action="">
<select name="select_data">
<option value="1000">Account Demo 1</option>
<option value="1035">Account Demo 2</option>
</select>
<input type="submit" onclick="sendForm('<?php echo $domainURL;?>page_1')" form="myForm" class="btn btn-primary btn-sm" value="Page 1">
<input type="submit" onclick="sendForm('<?php echo $domainURL;?>page_2')" form="myForm" class="btn btn-primary btn-sm" value="Page 2">
<script>
function sendForm(action)
{
document.getElementById('myForm').action = action;
document.getElementById('myForm').submit();
}
</script>
I did some testing, I change method to "get" and its work, but when I change method to "post" , it not able send anything.
I tried with
print_r($_GET);
print_r($_POST);
Get was able to retrieve the send value on a select option tag.
Same code, but post doesn't send through
I tried to do post
if action="" , its work fine
but if action="http://www.myowndomain.com/subpage/page/thepage.php" it does not work for post.

Instead of Javascript, use the formaction attribute:
<input type="submit" formaction="<?php echo $domainURL;?>page_1" class="btn btn-primary btn-sm" value="Page 1">
<input type="submit" formaction="<?php echo $domainURL;?>page_2" class="btn btn-primary btn-sm" value="Page 2">
THere's also no need for form="myForm" when the submit button is inside the <form> element.

Change <input type="submit"> to type="button" I hope it will work.

Related

button restriction alerts popover titles

I have the following scenario with the form bellow:
<form action="action.php">
<input type="text" id="input1" name="input2">
<input type="text" id="input2" name="input2">
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover
title" data-content="You don't have permission to press button">Button</button>
</form>
I need some Javascript code that says:
if input1=input2 submit form else popover title saying "You don't have permission ". I tried some stuff based on some search on the internet but it didn't really work

continue button and add button

I need you help, I have a form in PHP, javascript, HTML and MYSQL. I use a bootstrap for template.
I have a two button (continue button and add button)
<form class="form-horizontal form-label-left" action="PHP/GuardarMetodoque.php" method="POST" novalidate>
<div class="form-group">
<div class="btn-group btn-group-lg">
<button class="btn btn-primary" onclick="return continuar();">Continuar</button>
<button type="submit" class="btn btn-primary" onclick="return continuar();">Continuar</button>
<input type="hidden" name="metodoque" value="metodoque" />
<button type="submit" class="btn btn-primary" onclick="return continuar();">AƱadir Riesgo</button>
<input type="hidden" name="Anadirriesgo1" value="Anadirriesgo1" />
<input type="hidden" name="ID_proceso" value="<?php echo $_id; ?>">
<input type="button" class="btn btn-primary" value="Regresar" onclick="history.back(-1)" />
</div>
</div>
</form>
the continue button serves to pass another page and the add me button works to add data from the answered form.
as you see called the file "PHP/GuardarMetodoque.php" and it works but when you click continue, you save the form again, and what I want is for you to just send me the other form without saving anything
If you set button type to submit for continue button it will submit the form to mentioned action url, Try:
<button class="btn btn-primary" id="continue">Continue</button>
Add jquery to handle button click event:
$('#continue').click(function(){
//do your logic here
});

Code not working. The user is not being removed from the database.

<html>
<div class="container">
<div class="row vertical-center-row">
<div class="col-lg-12">
<div class="row">
<div class="col-xs-4 col-xs-offset-4">
<h3>Update/Remove Users</h3>
<br>
<div class="form-group">
<form method='POST' action='delete.php?rfidcode="<?php echo $_GET['rfidcode']?>"'>
<label for="name">Are you sure that want to delete this user?</label>
<button type="submit" name="submit" class="btn btn- primary">Yes
<button type="submit" onclick="window.location.href='http://localhost:8080/accesspi/users.php'" class="btn btn-primary">No </button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST["submit"])){
$sqladd = "delete from users where rfidcode = '".$_GET['rfidcode']."'";
//update
if (($conn->query($sqladd))) {
echo '<script language="javascript">';
echo 'alert("Successfully removed")';
echo '</script>';
}
}
?>
</html>
I have the following code, that doesn't work. It doesn't remove the user from the database and has also a problem on line 9 because it prints in the website "?>. The javascript code it is also not executed.
P.S The db.php file is included on the top of the code, but i didn't write it here. Can anyone help me ?
I suppose your delete doesn't work because isset($_POST["submit"]) is false. Why it can be false?
It's either not set or set to NULL.
Check your $_POST array - all chances there will be no key submit. This happens because you didn't set value attribute of submit button:
<button type="submit" name="submit" value="Submit" />
After that - check $_POST.
Your code have some errors try replacing this part...
<div class="form-group"><form method='POST' action='delete.php?rfidcode="<?php echo $_GET['rfidcode']?>"'><label for="name">Are you sure that want to delete this user?</label><button type="submit" name="submit" class="btn btn- primary">Yes</button> <button type="submit" onclick="window.location.href='http://localhost:8080/accesspi/users.php'" class="btn btn-primary">No </button></form></div>

PHP Form with multiple submit buttons

I have a form with Two buttons. It's a submit form which is basically there to increase/Decrease an Integer value in a MySQL database depending on which button they click.
This is a weird scenario, the page requires an ID extension;
appinfo.php?id=12
Whenever I click one of the buttons it changes the extension to:
appinfo.php?VoteYes=Yes
Ideally I'd like it so if someone clicks on Yes it will increase a value within an SQL query and if they click no, it will decrease it.
Here is what I have so far:
<form action="<?php echo $_SERVER['PHP_SELF'] . "?id=" . $_GET['id']; ?>"/>
<input id="submit" name="VoteYes" type="submit" value="Yes" class="btn btn-success"></input>
<input id="submit" name="VoteNo" type="submit" value="No" class="btn btn-warning"></input>
</form>
In your <form> add the attribute method="post". The default is GET which is changing your URL.
So, it should be:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?id=" . $_GET['id']; ?>"/>
<input id="submit" name="VoteYes" type="submit" value="Yes" class="btn btn-success"></input>
<input id="submit" name="VoteNo" type="submit" value="No" class="btn btn-warning"></input>
</form>
Then in your PHP code, check for $_POST instead of $_GET when checking for the submitted values.
Hope it helps!
If you really want the query string You can do this with hidden input that will include the id,
I also modified the names to make it less complicated
<form>
<input id="submit" name="Vote" type="submit" value="Yes" class="btn btn-success" />
<input id="submit" name="Vote" type="submit" value="No" class="btn btn-warning" />
<input name="id" type="hidden" value="<?php echo $_GET['id']?>" /></form>

angularjs ng-disabled doesn't add disabled to button

I have an input button that I want to set to disabled if a user selects a certain value from a select box:
Select menu:
<select id="jobstatus" name="jobstatus" ng-model="associate.JobStatus" class="form-control">
<option value="0">Current</option>
<option value="1">Former</option>
<option value="2">Never worked there</option>
</select>
Input Button:
<input type="submit" class="btn btn-info pull-right
btn-lg btn-block" ng-disabled="{{associate.JobStatus === '2'}}" />
Now when I am viewing the source, when I do select option 2, the input button element changes from value ng-disabled="false" to ng-disabled="true" but the disabled attribute is not applied to the button.
What am I doing wrong here?
Use this
<input type="submit" class="btn btn-info pull-right btn-lg btn-block" ng-disabled="associate.JobStatus == 2" />
Angular Doc ngDisabled
Curly braces means the notation {{ }} to bind expressions to elements is built-in Angular markup.
Use:
<input type="submit" ng-disabled="associate.JobStatus == 2" />
Instead of:
<input type="submit" ng-disabled="{{associate.JobStatus == 2}}" />
same as for ng-show / ng-hide / ng-if, you can use the model
expression itself instead of {{}}
For Example:-
Use:
<div ng-show="someObject.showProperty">
Instead of:
<div ng-show="{{someObject.showProperty}}">
You have to use like this.
<input type="submit" class="btn btn-info pull-right
btn-lg btn-block" ng-disabled="associate.JobStatus === '2'" />

Categories