1st form within table not submitting - php

I have a while loop generated table that looks like the following:
<table>
<tr>
<th>Date</th>
<th>Pushups</th>
<th>Delete</th>
</tr>
<tr>
<td>11-01-2012</td>
<td>28</td>
<td>
<form action="../workout_tracker/delete_pushups.php" method="get" id="Delete1">
<input type="hidden" value="253" name="pushups_id" />
<input type="hidden" value="/workout_tracker/pushups-tracker/" name="current_page" />
<input type="submit" value="Delete" form="Delete1" />
</form>
</td>
</tr>
<tr>
<td>11-02-2012</td>
<td>33</td>
<td>
<form action="../workout_tracker/delete_pushups.php" method="get" id="Delete2">
<input type="hidden" value="246" name="pushups_id" />
<input type="hidden" value="/workout_tracker/pushups-tracker/" name="current_page" />
<input type="submit" value="Delete" form="Delete2" />
</form>
</td>
</tr>
<tr>
<td>11-03-2012</td>
<td>43</td>
<td>
<form action="../workout_tracker/delete_pushups.php" method="get" id="Delete3">
<input type="hidden" value="39" name="pushups_id" />
<input type="hidden" value="/workout_tracker/pushups-tracker/" name="current_page" />
<input type="submit" value="Delete" form="Delete3" />
</form>
</td>
</tr>
</table>
The problem is that the first "Delete" form in the first row of the table isn't submitting. When I click, it doesn't do anything.
There is a form higher up on the page, but it closes and has validated. I get the same response in Chrome, Firefox, and IE.
UPDATE:
In a different form higher in the markup (not shown), the form tag had not been closed. I had </for>...

Do any of the other delete forms work or is it just the first one?
Open up your browser console/debugger and look for any errors on page load or when you click the button.
The only thing that looks as a possible problem is the form attribute of the submit input element. The link below shows that it's new in HTML5 and the only browser that doesn't support it yet is IE. It could be that you need to update to the latest version of your browser.
http://www.w3schools.com/tags/att_input_form.asp

Related

2 forms on same page php

My studybook gives me an assignment which requires me to have 2 forms on one page and output them both to the same page. Is this even possible? Both forms work fine independently. Both have the action:
<?php echo $_SERVER['PHP_SELF']; ?>".
Both have a submit button, but the button only submits the form it's part of. This probably makes sence though.
Thing is i need the page to either post both form outputs when clicking one of the 2 submit buttons or press them subsequently but the information from the first form needs to stay on the page.
Is this possible or am i trying do to the impossible?
the forms are as follows;
form 1:
<form name="orderform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Korting:
<tr>
<td>
<input type="checkbox" name="korting[]" value=15 /> Student 15% <br>
<input type="checkbox" name="korting[]" value=10 /> Senior 10% <br>
<input type="checkbox" name="korting[]" value=5 /> Klant 5% <br>
<hr />
</td>
</tr>
<tr>
<td>
betalingswijze
<input type="radio" name="betalingswijze" value="paypal"> Paypal
<input type="radio" name="betalingswijze" value="mastercard"> Mastercard
<input type="radio" name="betalingswijze" value="visa"> Visa
<hr />
</td>
<tr>
<td>
<img src="toshiba.jpg" alt=" " />
</td>
</tr>
<tr>
<td>
Toshiba Sattelite A100-510 Basisprijs 999.99
</td>
</tr>
<tr>
<td><!--Shopping Cart Begin-->
<input type="hidden" name="toshibaproduct" value="001" />
<input type="hidden" name="toshibamerk" value="toshiba" />
<input type="hidden" name="toshibamodel" value="Sattelite A100-510" />
Operating system <select name="toshibaos" value="Toshiba">
<option value="xp">Windows XP</option>
<option value="vista">Windows Vista</option>
<option value="linux">Linux</option>
</select>
Aantal: <input type="text" size=2 maxlength=3 name="toshibaaantal" value="0" />
<input type="hidden" name="toshibaprijs" value="999.99" />
<input type="image" src="bestel.jpg" border=0 value="bestellen" />
<hr />
<tr>
<td>
<img src="acer.jpg" alt=" " />
</td>
</tr>
<tr>
<td>
Acer Aspire 5735Z Basisprijs 529.99
</td>
</tr>
<tr>
<td>
<input type="hidden" name="acerproduct" value="002" />
<input type="hidden" name="acermerk" value="acer" />
<input type="hidden" name="acermodel" value="Aspire 5735Z" />
Operating system <select name="aceros" value="Acer">
<option value="xp">Windows XP</option>
<option value="vista">Windows Vista</option>
<option value="linux">Linux</option>
</select>
Aantal: <input type="text" size=2 maxlength=3 name="aceraantal" value="0" />
<input type="hidden" name="acerprijs" value="529.99" />
<input type="image" src="bestel.jpg" border=0 value="bestellen" />
<hr />
</td><!--Shopping Cart End-->
</tr>
</form>
Form 2
<form name="klant gegevens" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border=1 >
<tr>
<td colspan="2">
<b>Factuur klantgegevens</b>
</td>
</tr>
<tr>
<td width="100">Naam: </td>
<td>
<input type="text" sie="55" name="naam" />
</td>
</tr>
<tr>
<tr>
<td>Adres: </td>
<td>
<input type="text" sie="55" name="adres" />
</td>
</tr>
<tr>
<td>Woonplaats:</td>
<td>
<input type="text size="34" name="woonplaats">
Postcode:<input type="text" size="6" name="postcode">
</td>
</tr>
<tr>
<td>e-mail:</td>
<td>
<input type="text" size="55" name="email">
</td>
</tr>
<tr>
<td>Feedback:</td>
<td>
<textarea cols="40" rows="3" name="commentaar">
</textarea>
</td>
</tr>
</table>
<input type="image" src="checkout.png" value="send"/>
</form>
Both have functions which kick in on submit. Sorry for the spacings. I have them better in my own files but i just don't know how to get them right on this site.
Greetings,
Lennart
The action represent the page that will receive the posted data. You may use differents actions or the same action with different parameters.
If you use the same action, you had to insert a parameter that permit to manage different cases. You may insert an hidden field to do this.
Consider these simple forms:
<form name="form_a" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="form" value="A">
<button type="submit">Form A</button>
</form>
<form name="form_b" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="form" value="B">
<button type="submit">Form B</button>
</form>
To manage the different submission, you had to check the value of the hidden field:
if(isset($_POST['form'])){
switch ($_POST['form']) {
case "A":
echo "submitted A";
break;
case "B":
echo "submitted B";
break;
default:
echo "What are you doing?";
}
}
You can't submit two separate forms at the same time, because each submission represent a different request to the server.
You may merge manually the fields of the two forms, or use Javascript to do this for you.
Keep in mind that if you do this via Javascript, the field of the forms had to have differents names.
As you caan see here you can do simply via jQuery:
var str1 = $("form_a").serialize();
var str2 = $("form_b").serialize();
$.post(url, str1 + "&" + str2);
Where url is the action params of the form
Your form should be like this.
First form
<form method="post" >
...
<input type="hidden" name="form1submission" value="yes" >
<input type="submit" name="submit" value="Submit" >
</form>
Second form
<form method="post" >
...
<input type="hidden" name="form2submission" value="yes" >
<input type="submit" name="submit" value="Submit" >
</form>
And your php for first form.
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['form1submission'])) {
// first form code.
}
And second form php code.
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['form2submission'])) {
// second form code.
}
That's it.
DUPLICATE POST
Yes you can!
First, add the proper action to all forms, secondly, give them an unique name
HTML Side
Don't forget to add the http method what you want (GET or POST)
<form method="post">
<input type="hidden" name="orderform" />
<!-- rest of form goes here -->
</form>
<form method="post">
<input type="hidden" name="klant_gegevens" />
<!-- rest of form goes here -->
</form>
Leaving the action-attribute empty or removing it entirely will make the form submit to the current page (see this post), and usage of $_SERVER["PHP_SELF"] can lead to XSS-injection read under "Big Note on PHP Form Security"
Note:
Avoid using space for field names, it can make some problem to match them...
PHP Side
getting input values, by filtering on received form name
if (isset($_POST["orderform"])) {
// The first form was submitted
}
if (isset($_POST["klant_gegevens"])) {
// The second form was submitted
}
Note:
Use print_r() or var_dump(), to debug the content of exchanged values

How to update the data in particular table row in HTML?

Since the <form> can not inside <tr>, I can not assign the form for each row. And at the end I have create a from like this
<form>
<table>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
</table>
</form>
So, it seems when I submit data it submit every input, how can I send only a specific row? Thanks
Since forms send all the values, (since your using <button>), you could assign each row a key that corresponds to that row. Then use that in the textbox. Note: Textbox values must be an array structure, so that particular key from the submit update can be used (kinda like filtering). Consider this example:
<?php
if(isset($_POST['update'])) {
$product_key = $_POST['update'];
$product_name = $_POST['my_product_name'][$product_key];
echo $product_name;
// this should correspond to that same textbox row that you selected
}
?>
<form method="POST" action="">
<table>
<tr>
<td><input type="text" name="my_product_name[1]"></td>
<td><button name="update" type="submit" value="1">Update</button></td>
</tr>
<tr>
<td><input type="text" name="my_product_name[2]"></td>
<td><button name="update" type="submit" value="2">Update</button></td>
</tr>
</table>
</form>
This is not possible. A form sends everything in it. You have to use multiple forms in order to do that. Can you explain why you want to send each row separately. Let us know the complete problem so we can provide you much better solution :)
You must use separate forms. To avoid this issue, you could try using div's and style them with css.
<div class="big-wrapper">
<div class="form-wrapper">
<form id="first-input">
<input name="my_product_name">
<button type="submit">Click Here To Submit Form 1</button>
</form>
</div>
<div class="form-wrapper">
<form id="second-input">
<input name="my_product_name">
<button type="submit">Click Here To Submit Form 2</button>
</form>
</div>
Example of above code (with no additional css): http://postimg.org/image/p0olzl933/
One method would be to have form tags that wrap tables and each table effectively becomes a row.
Honestly, there are a lot of ways to do this... you could handle it using Javascript with something like I have below or generating a special table with a server-side script and writing that to the page. You could use ajax calls to send the values that change to a web service, etc.
Hope that thelps.
<form>
<table>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
</table>
</form>
<form>
<table>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
</table>
</form>
...
Collect the value then push it into the form on submit.
<script>
function dosubmit(e){
var value = $(this).parents('tr').find('input.some').val();
$(this).parents('tr').find('input.my_product_name').val(value);
}
</script>
<table>
<tr>
<td><input name="some"/></td>
<td>
<form onsubmit="dosubmit(event)">
<input type="hidden" name="my_product_name"/>
<input type="submit" value="Submit">
</form>
</td>
</tr>
<tr>
<td><input name="some"/></td>
<td>
<form onsubmit="dosubmit(event)">
<input type="hidden" name="my_product_name"/>
<input type="submit" value="Submit">
</form>
</td>
</tr>
<tr>
<td><input name="some"/></td>
<td>
<form onsubmit="dosubmit(event)">
<input type="hidden" name="my_product_name"/>
<input type="submit" value="Submit">
</form>
</td>
</tr>
</table>
I don't know how much good a jsbin will be, but here it is
You can submit the value in form by setting in hidden parameter as follows:
HTML:
<form action="" id="formId">
<input type="hidden" name="product_name" id="hiddenValue" />
</form>
<table>
<tr>
<td><input name="my_product_name"></td>
<td><button type="submit" onclick="submitForm(this)"></td>
</tr>
<tr>
<td><input name="my_product_name"></td>
<td><button type="submit" onclick="submitForm(this)"></td>
</tr>
</table>
Script:
<script>
function submitForm(id){
var input = id.parentElement.parentElement.getElementsByTagName("input")[0].value;
//Retrieving value of specific rows
document.getElementById("hiddenValue").value = input;
//Submits the form with given id.
document.getElementById("formId").submit();
}
</script>

How to submit two php forms to one location

I have two php forms, both for registration means (enter name, username, password etc). My first registration form (reg1.php) contains the basic inputs as I mentioned above and then I have a second registration form (reg2.php) that includes checkboxes where the form would ask the user other questions before finalizing their sign up.
What I am having trouble with is that when I enter data into my inputs in the first registration form, then proceed to the next registration page and fill that out and click Sign Up, my output on my server only obtains the information I inputted in the second registration page, not the first.
How can I get both inputted data from the two registration pages to appear together? I have been told about POSTBACK to help with this but I am not all that familiar with how to use it.
First php page:
<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table style="width:300px">
<form name="Rego" method="post" action="rego2.php">
<tr>
<td><label>Name:</label></td>
<td><input type="text" name="fname"/></td>
</tr>
<tr>
<td><label>Username:</label></td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td><label>Password:</label></td>
<td><input type="password" name="password" id="pass" /></td>
</tr>
<tr>
<td><label>Confirm Password:</label></td>
<td><input type="password" name="conpassword" id="conpass"/></td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Next Page">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>
Second php page
<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table>
<form name="Rego" method="post" action="http://myserver...">
<tr>
<td>
<input type="checkbox" name="checkbox" value="Agree to T&C">I agree to the Terms and Conditions<br>
<input type="checkbox" name="checkbox" value="No Criminal Records">I have no criminal associations<br>
</td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Sign Up">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>
When the first form is submitted either store the data in a $_SESSION variable and retrieve it when you process the second form, or write it to hidden <input> elements on your second form and retrieve it from the $_GET or $_POST array
In 2nd input form you take first inout from value and keep those one as hidden.
and 2nd input form you should
<body>
<?php include("menu.php"); ?>
<div id="main">
<h2>Sign Up</h2>
<table>
<form name="Rego" method="post" action="http://myserver...">
<input type="hidden" name="fname" value="<?php echo $_POST['fname'];?> " />
<input type="hidden" name="username" value="<?php echo $_POST['username'];?> " />
<input type="hidden" name="passowrd" value="<?php echo $_POST['password'];?> " />
<input type="hidden" name="conpassowrd" value="<?php echo $_POST['conpassword'];?> " />
<tr>
<td>
<input type="checkbox" name="checkbox" value="Agree to T&C">I agree to the Terms and Conditions<br>
<input type="checkbox" name="checkbox" value="No Criminal Records">I have no criminal associations<br>
</td>
</tr>
<tr>
<td><p><input class="button" type="submit" value="Sign Up">
<input class="button" type="reset" value="Reset"></p></td>
</tr>
</form>
</table>
</div>
</body>
I hope it will work for you.
In the second page, you can get the post data from page 1 and set it in a hidden field like this, say the fname:
<input type="hidden" name="fname" id="fname" value="<?php echo $_POST['fname'] ?>">
When you submit from the second page, you can catch this data in the destination page, say
$_POST['fname']

Sending form data to PayPal checkout

Ok here is problem, I am sending form data via radio buttons to a PayPal checkout but it works when you first upload the php file and takes the correct values, but if you return and select say the next radio button and submit it then changes the submit info to the value you sent before almost overiding it?
<table class="procut_item" border="0" cellpadding="4">
<tr>
<td width="auto"><h4>Product test</h4></td>
<td width="auto"><form method="post" action="process.php">
<input type="hidden" name="itemprice" value="10" />
<input type="hidden" name="itemQty" value="1" />
Size:<input type="radio" name="itemname" value="1">10 x 10</select>
<input class="dw_button" type="submit" name="submitbutt" value="Buy" />
</td>
<tr>
<tr>
<td width="auto"><h4>Product test</h4></td>
<td width="auto"><form method="post" action="process.php">
<input type="hidden" name="itemprice" value="30" />
<input type="hidden" name="itemQty" value="1" />
Size:<input type="radio" name="itemname" value="1">10 x 10</select>
<input class="dw_button" type="submit" name="submitbutt" value="Buy" />
</td>
<tr>
</table>
With seeing all of the code and how it is being handled, my first guess would be that you are usnig the same variable name, and it is overriding the first. You could could create an array if not already using one, or increment the variable name by appending a number to it.

Multiple Submit Buttons in HTML

For testing purpose I designed simple HTML form as follows
<html>
<head>
<title>Test Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table border="0" align="center">
<tbody>
<tr>
<td>First Name</td>
<td><input type="text" name="txtfname" value="" size="10" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="txtlname" value="" size="10" /></td>
</tr>
<tr>
</tbody>
</table>
</body>
</html>
Now on this single HTML page I want to perform basic SQL functionality with MySQL using PHP. I want 4 submit buttons (Insert Delete Update Search) on single HTML form. I tried it by taking DIV tag but still its not working. Any suggestions???
<form method="post">
<table border="0" align="center">
<tbody>
<tr>
<td>First Name</td>
<td><input type="text" name="txtfname" value="" size="10" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="txtlname" value="" size="10" /></td>
</tr>
<tr>
<input type="submit" name="insert" value="insert" />
<input type="submit" name="update" value="update" />
<input type="submit" name="delete" value="delete" />
<input type="submit" name="search" value="search" />
</tr>
</tbody>
</table>
</form>
Now you can check which button was used to submit using regular php stuff isset() like below.
<?php
if(isset($_POST['insert'])) {
//perform insert
}
if(isset($_POST['search'])) {
// perform search
}
?>
u mean to ask u want to perform 4 action's.
just use an ajax call on onClick action of each button.
do not create a form, just make a function call.
You can create four forms on your HTML page as following
<form action="insert.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
<form action="delete.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
<form action="update.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
<form action="search.php" method="post">
<!-- Some form data here -->
<input type="submit">
</form>
from your question I understand above scenario
Hope it helps
you can do tat using this code...
<input type="button" onclick="var e = document.getElementById('form_id'); e.action='adress1'; e.submit();" value="submit1">
<input type="button" onclick="var e = document.getElementById('form_id'); e.action='adress2'; e.submit();" value="submit2">
<input type="button" onclick="var e = document.getElementById('form_id'); e.action='adress3'; e.submit();" value="submit3">

Categories