one button two actions - php

i want to submit data from one button in the databse and the same button should export
the CSV of the databse, i tried but it doesn't work only dat is being sent
i have two buttons
<div class="mws-form-item large">
<input type="submit" class="button" name="submit1" value="Generate Serials" />
<a href="get_csv.php" style="text-decoration:none">
<input type="button" name="get_csv" value="Export CSV"/></a>
</div>
and tried the in the following way
<div class="mws-form-item large">
<a href="get_csv.php" style="text-decoration:none">
<input type="submit" class="button" name="submit1" value="Generate Serials" />
</a>
</div>

If you can use jQuery, then you can bind click event to the submit button and perform all the operations you need in the function being called after click.
For eg :
<input type="submit" id="submitBut">
For this you can have :
$("#submitBut").click(function(){
//operations you need to perform
})

Related

Bootstrap Modal Form Submit

I have implemented a working Modal form using HTML, Bootstrap CSS and PHP, which displays information about a document. In the footer of the Modal I have a 'Delete Document' button which should post to the same page (index.php). The form doesn't react to the submit button.
Reading up on the subject a lot of people are using AJAX to submit from a Bootstrap Modal. This seems unnecessary? Do I really need to implement a JSON post in AJAX just to submit this Modal?
The code:
<div class="modal-footer">
<form action="index.php" method="post">
<input type="hidden" name="DocumentID" value="<?php echo $row['DocumentID']; ?>" />
<input type="hidden" name="top-search" value="<?php echo $_POST['top-search']; ?>" />
<button type="submit" name="deleteDocument" class="btn btn-w-m btn-danger" onclick="return confirm('Are you sure you want to delete this Document?')">Delete</button>
</form>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
I have an example where a Modal submits successfully although to a different page using a similar method but using target="_blank"
Its not onclick - but onClick.
Also, you need to place the scripts inside {}. The following code should work.
/*
* A simple React component
*/
class Application extends React.Component {
render() {
return (<div class="modal-footer">
<form action="index.php" method="post">
<input type="hidden" name="DocumentID" value="<?php echo $row['DocumentID']; ?>" />
<input type="hidden" name="top-search" value="<?php echo $_POST['top-search']; ?>" />
<button type="submit" name="deleteDocument" class="btn btn-w-m btn-danger" onClick={ function() {
return confirm("Yes/No?");
}}>Delete</button>
</form>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>);
}
}
/*
* Render the above component into the div#app
*/
React.render(<Application />, document.getElementById('app'));

Performs form action even out of the form

Hi having a problem with this code even if i clicked on cancel it will still proceed to use the action of my form even though the CANCEL button is not part of the form, Would appreciate any help.
Here is the code.
<form method="post" action="input_enroll.php" >
<div id="overlay1">
<div>
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" >
<input type="submit" value="Proceed To Enroll" '>
</form>
<input type="submit" value="Cancel" onclick='overlay()'>
</div>
</div>
EDIT: Any suggestions what would be a better idea? I'm thinking putting the cancel outside the div.
You are having form started, then divs started, then form closed..start form after divs..
as your markup is not correct, browsers will change it as thier parser suggest,
In chrome </form> tag is postponed after </div>s..
<div id="overlay1">
<div>
<form method="post" action="input_enroll.php" >
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" />
<input type="submit" value="Proceed To Enroll" />
</form>
<input type="submit" value="Cancel" onclick='overlay()' />
</div>
</div>

Form with two button submit with different value

<form action="here.php" method="POST">
<input type="text" name="text">
<div id="one">
<input type="hidden" name="aaa" value="one">
<input type="submit" value="Send">
</div>
<div id="two">
<input type="hidden" name="aaa" value="two">
<input type="submit" value="Send">
</div>
</form>
Now if i click on Send of div ONE or div TWO i have always in $_POST['aaa'] = 'two';
Is possible make one form with two submit with different values?
If i click on div one submit i would like reveice $_POST['aaa'] = 'one' and if i click on div two submit i would like receive $_POST['aaa'] = 'two'.
How can i make it?
I can use for this PHP and jQuery.
EDIT:
I dont want create two form - i dont want showing two many times <input type="text" name="text">
EDIT: maybe i can instead button submit ? but how?
It seems that what you actually want to do is have a value in each of the buttons, see this, for example:
<form action="demo_form.asp" method="get">
Choose your favorite subject:
<button name="subject" type="submit" value="fav_HTML">HTML</button>
<button name="subject" type="submit" value="fav_CSS">CSS</button>
</form>
You'd need two different forms:
<div id="one">
<form ...>
<input type="hidden" name="aaa" value="one">
<input type="submit" value="Send">
</form>
</div>
<div id="two">
<form ...>
<input ...>
<input ...>
</form>
</div>
Standard practice is that when two fields have the exact same name, to use only the LAST value encountered in the form and submit that.
PHP does have a special-case notation (name="aaa[]") to allow submitting multiple values with the same name, but that wouldn't help you here, as that'd submit ALL of the aaa values, not just the one closest to the submit button.
HTML form:
<form ...>
<input type="text" name="textfield">
<div id="one">
<input type="hidden" name="one_data" value="aaa" />
<input type="submit" name="submit_one" value="Submit" />
</div>
<div id="two">
<input type="hidden" name="two_data" value="bbb" />
<input type="submit" name="submit_two" value="Submit" />
</div>
</form>
server-side:
if (isset($_POST['submit_two'])) {
$data = $_POST['two_data'];
} else if (isset($_POST['submit_one'])) {
$data = $_POST['one_data'];
} else {
die("Invalid submission");
}
Instead of showing two submit button, you can show a radio list with two options and one submit button.
Try this:
in html-
<input id="PreviousButton" value="Previous" type="submit" />
<input id="NextButton" value="Next" type="submit" />
<input id="Button" name="btnSubmit" type="hidden" />
in jOuery-
$("#PreviousButton").click(function () {
$("#Button").val("Previous");
});
$("#NextButton").click(function () {
$("#Button").val("Next");
});
then you can see in the form results - what "Button" contains.

How to deal with two submit buttons in a form?

I don't understand this,
if I do this and I click the check out button, the page won't go to the check out page,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
It only does if I change the name="checkout" to name="cart-checkout",
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="cart-checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
It works that way but does not make any sense to me, do you know why it does it that way?
So I tried to use <a> tag inside the <button> tag and it goes to the check out page,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
But does it a valid html to put <a> tag inside the <button> tag?
Why not change the buttons to:
<input name="update" id="update" type="submit" value="Update cart">
<input name="cart-checkout" id="checkout" type="submit" value="Check out">
Then in PHP (on cart.php) you can do:
<?php
if($_POST){
if(isset($_POST['update']){
// process update
} else if(isset($_POST['cart-checkout']){
// process cart checkout
// or uncomment the below line to forward to checkout.php
// header("Location: checkout.php");
}
}
?>
What about making one <button> that simply acts like a <a href=""> ?
-edit-
Whoops, sorry, misread. <button onclick="window.location='/nextpage';"> ?
I would actually use JavaScript here with an onclick event, which will take you to the checkout page.

Open PHP Page On Button Click

I wonder whether someone could help me please.
I'm put together the following form contained within a PHP file.
<form name="savemyfindstolocation" id="savemyfindstolocation" method="post">
<p><label></label>
</p>
<p align="left">
<input name="userid" type="text" id="userid"/>
<input name="locationid" type="text" id="locationid"/>
<br />
</p>
<div>
<label>
<div align="left">Click on the map to place the marker for the find that has been made and drag until the precise location has been found. </div>
</div>
<p align="left"><label>Find OSGB36 Latitude Co-ordinate<br />
</label>
</p>
<div>
<div align="left">
<input name="findosgb36lat" type="text" id="findosgb36lat" size="20" />
</div>
</div>
<p align="left"><label>Find OSGB36 Longitude Co-ordinate<br />
</label>
</p>
<div>
<div align="left">
<input name="findosgb36lon" type="text" id="findosgb36lon" size="20" />
</div>
</div>
<p align="left"><label>Date of Trip<br />
</label>
</p>
<div>
<div align="left">
<input name="dateoftrip" type="text" id="dateoftrip" size="10" />
</div>
</div>
<input name="submit" type="submit" onclick="MM_callJS('savedata()')" value="Submit" />
</form>
It all works fine, but I'd now like to add a button that opens the following php page, 'blobupload.php'. If I've understood this correctly from the research that I've done, I need to use javascript to open the page, using the 'submit' action from the main form.
What I don't understand is how to do this when the 'submit' action is already taken for the saving of the information on the main form.
Could someone perhaps please show me how to get around this, i.e. using the same 'submit action but for two different purposes.
Just modify your form tag (add the action attribute to file you want to load):
<form name="savemyfindstolocation" id="savemyfindstolocation" method="post" action="blobupload.php">
And you submit input tag:
<input name="submit" type="submit" value="Submit" />
You can use a second javascript function to open new window like this way
<input name="submit" type="submit" onclick="MM_callJS('savedata()');SECOND_JS_FUNCTION()" value="Submit" />
Use php to process the form is one of the way to do it.
<input name="submit" !!!!!!action="process.php" method="POST (or get)!!!!!!!!!! type="submit" onclick="MM_callJS('savedata()')" value="Submit" />
that way the the variable will be passed to the process.php while you can also redirect the page in the process.php
header("Location:URL");

Categories