Render form within html table - php

I'm trying to render an html form within a table. The problem is I load the page with AJAX and after that the button stops working (due to the tr and td placement).
Is there any way to manage this with html, javascript, php, or css?
This is what I'm trying to accomplish:
echo "<tr id=\"$I_ID\" class=\"toggleEdit\">";
echo "<form class=\"editRow\" name=\"editRow\" action=\"\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"edit\">";
echo "<input type=\"hidden\" name=\"$thatTable\">";
echo "<input type=\"hidden\" value=\"$I_ID\" name=\"I_ID\">";
echo "<input type=\"hidden\" value=\"$row[1]\" name=\"$columns[1]\">";
echo "<td>$row[1]</td>";
for ($pointer = 2 ; $pointer < $countRows ; ++$pointer) {
echo "<td><input type=\"text\" value=\"$row[$pointer]\" name=\"$columns[$pointer]\"></td>";
}
echo "<td><input type=\"submit\" id=\"submitEdit\" value=\"submit edit\"></td>";
echo "</form>";
echo "</tr>";
And this is what works:
echo "<tr id=\"$I_ID\" class=\"toggleEdit\">";
echo "<td id=\"tdEditRow\">";
echo "<form class=\"editRow\" name=\"editRow\" action=\"\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"edit\">";
echo "<input type=\"hidden\" name=\"$thatTable\">";
echo "<input type=\"hidden\" value=\"$I_ID\" name=\"I_ID\">";
echo "<input type=\"hidden\" value=\"$row[1]\" name=\"$columns[1]\">";
echo "$row[1]";
for ($pointer = 2 ; $pointer < $countRows ; ++$pointer) {
echo "<input type=\"text\" value=\"$row[$pointer]\" name=\"$columns[$pointer]\">";
}
echo "<input type=\"submit\" id=\"submitEdit\" value=\"submit edit\">";
echo "</form>";
echo "</td>";
echo "</tr>";

Related

PHP Basket quantity variable

I am trying to create a php page where the materials from database are populated. Users should be able to enter the quantity next to the item they wish to order and I have created a qty text field for this
<?php
session_start();
include("db.php");
$pagename="Order Material";
echo "<html>";
echo "<title>".$pagename."</title>";
echo "<h2>".$pagename."</h2>";
include ("detectlogin.php");
echo "<link rel=stylesheet type=text/css href=mystylesheet.css>";
$sql="select * from material";
$result=mysqli_query($con, $sql) or die(mysqli_error($con));
echo "<table border=1>";
echo "<tr>";
echo "<th>Material Name</th>";
echo "<th>Material Description</th>";
echo "<th>Toxicity Level</th>";
echo "</tr>";
while ($arraymaterials=mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$arraymaterials['materialName']."</td>";
echo "<td>".$arraymaterials['materialDescrip']."</td>";
echo "<td>".$arraymaterials['materialToxicity']."</td>";
echo "<td>Enter Quantity</td>";
echo "<td><input type=text name=qty value=qty size=5></td>";
echo "<form action=request_material.php method=post>";
echo "<input type=hidden name=materialcode value=".$arraymaterials['materialCode'].">";
echo "<td><input type=submit value='Request'></td>";
echo "</form>";
echo "</tr>";
}
echo "</table>";
?>
However, I cannot successfully post the value of qty on to the next page even though I have $qty=$_POST['qty']; on my request_material.php. Do you know why this value entered in the qty field cannot be posted onto the request_material.php page? Do I need a session variable?
thanks
Because input tag name="qty" is outside the form tag
echo "<td><input type=text name=qty value=qty size=5></td>";// outside form tag
echo "<form action=request_material.php method=post>";
echo "<input type=hidden name=materialcode value=" . $arraymaterials['materialCode'] . ">";
echo "<td><input type=submit value='Request'></td>";
echo "</form>";
You need to add it inside your form tag as
echo "<form action=request_material.php method=post>";
echo "<td><input type=text name=qty value=qty size=5></td>";// add inside it
echo "<input type=hidden name=materialcode value=".$arraymaterials['materialCode'].">";
echo "<td><input type=submit value='Request'></td>";
echo "</form>";
Please try this: I have updated the code:
echo "<table border=1>";
echo "<tr>";
echo "<th>Material Name</th>";
echo "<th>Material Description</th>";
echo "<th>Toxicity Level</th>";
echo "</tr>";
if(mysqli_num_rows($result)>0)
{
echo "<form action=request_material.php method=post>";
while ($arraymaterials=mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$arraymaterials['materialName']."</td>";
echo "<td>".$arraymaterials['materialDescrip']."</td>";
echo "<td>".$arraymaterials['materialToxicity']."</td>";
echo "<td>Enter Quantity</td>";
echo "<td><input type='text' name='qty[]' value='qty' size=5></td>";
echo "<input type=hidden name='materialcode[]' value=".$arraymaterials['materialCode'].">";
echo "<td><input type=submit value='Request'></td>";
echo "</tr>";
}
echo "</form>";
}
echo "</table>";
In request_material.php check value of $qty.It will be an array.for more details print_r($_POST) in request_material.php

track change in an array then submit the array to the same page

I have the following php code (I omitted the irrelevant part of code):
<?php
echo "<form action=$_SERVER[PHP_SELF] method=\"POST\">";
echo "<table>";
for ($i=0;$i<$num_rows;$i+=1) {
echo "<tr>";
echo "<td align=center>$variable1[$i]</td>";
echo "<td align=center>$variable2[$i]</td>";
echo "<td align=center><input type=\"text\" name=\"variable3[$i]\" value=\"$variable3[$i]\" /></td></tr>";
echo "<input type=\"hidden\" name=\"variable1[$i]\" value=\"$variable1[$i]\">";
echo "<input type=\"hidden\" name=\"variable2[$i]\" value=\"$variable1[$i]\">";
echo "<input type=\"hidden\" name=\"variable3[$i]\" value=\"$variable1[$i]\">";
}
echo "<tr><td colspan=\"3\"><input name=\"action\" type=\"submit\" value=\"Update\"></td></tr>";
echo "</table>";
echo "</form>";
?>
I want to pass the variables through POST method to the same page. The code retrieves data from the database and lists it in a table. However, I want to be able to manually modify variable3 and submit the array after I do this. The problem is that the array is submitted before I modify the variable3. How can I submit the array with the value of variable3 modified? How can I check if variable3 was modified and do the submitting afterwards? Thanks.
delete line 11 like this
<?php
echo "<form action=$_SERVER[PHP_SELF] method=\"POST\">";
echo "<table>";
for ($i=0;$i<$num_rows;$i+=1) {
echo "<tr>";
echo "<td align=center>$variable1[$i]</td>";
echo "<td align=center>$variable2[$i]</td>";
echo "<td align=center><input type=\"text\" name=\"variable3[$i]\" value=\"$variable3[$i]\" /></td></tr>";
echo "<input type=\"hidden\" name=\"variable1[$i]\" value=\"$variable1[$i]\">";
echo "<input type=\"hidden\" name=\"variable2[$i]\" value=\"$variable1[$i]\">";
}
echo "<tr><td colspan=\"3\"><input name=\"action\" type=\"submit\" value=\"Update\"></td></tr>";
echo "</table>";
echo "</form>";
?>
Now you can see if it has been changed by cheking the value of $_POST['variable3'].

HTML form with multiple embedded tables, a lot of white space at top of page

I am having issues with a form I am trying to do in .php
I used tables, within the form, to format how I want the form to look like. The form is working correctly. But when I load the page, there is a huge white space at the top of the page, but I have no idea why it is there. I have tried looking at the source code in the web browser, and there are no html white space characters or anything out of the ordinary. Here is my code:
<?php
$strRequester = $_SERVER['PHP_SELF'];
echo "<div align=center>\n";
echo "<form name='SandwichOrder' action='$strRequester' method='POST'>\n";
####Bread####
echo "<table>\n";
echo "<tr><td bgcolor='CCCCCC'><input type='radio' name='size' value='whole'><b>Whole Sandwich</b></td>\n";
echo "<td bgcolor='CCCCCC'><input type='radio' name='size' value='half'><b>Half Sandwich</b></td></tr>\n";
echo "<tr><td> </td><td> </td></tr>\n";
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Roll/Bread:</b></td><td></td></tr><br>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='whiteroll'>White French Roll</td><br>\n";
echo "<td><input type='radio' name='bread' value='sourroll'>Sour Dough Roll</td><br>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='wheatroll'>Wheat French Roll</td><br>\n";
echo "<td><input type='radio' name='bread' value='dutchcrunch'>Dutch Crunch</td><br>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='nyrye'>New York Rye</td>\n";
echo "<td><input type='radio' name='bread' value='soursliced'>Sour Dough Bread</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='wheatsliced'>100% Whole Wheat Bread</td>\n";
echo "</tr>\n";
####Meat####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Meat:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='roastbeef'>Roast Beef</td>\n";
echo "<td><input type='radio' name='meat' value='turkey'>Turkey</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='everroastchicken'>EverRoast Chicken</td>\n";
echo "<td><input type='radio' name='meat' value='ham'>Ham</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='salami'>Salami</td>\n";
echo "<td><input type='radio' name='meat' value='pastrami'>Pastrami</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='tune'>Tuna</td>\n";
echo "<td><input type='radio' name='meat' value='chickensalad'>Chicken Salad\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='veggiepatty'>Veggie Patty</td>\n";
echo "<td><input type='radio' name='meat' value='vegetarian'>Vegetarian</td>\n";
echo "</tr>\n";
####Cheese####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Cheese:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='cheese' value='cheddar'>Cheddar Cheese</td>\n";
echo "<td><input type='radio' name='cheese' value='swiss'>Swiss Cheese</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='cheese' value='pepperjack'>Pepper Jack Cheese</td>\n";
echo "<td><input type='radio' name='cheese' value='american'>American Cheese</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='cheese' value='provolone'>Provolone Cheese</td>\n";
echo "<td><input type='radio' name='cheese' value='none'>No Cheese</td>\n";
echo "</tr>\n";
####Condiments####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Condiments:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='mayonnaise' value='mayonnaise'>Add Mayonnaise</td>\n";
echo "<td><input type='checkbox' name='mustard' value='mustard'>Add Mustard</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='lettuce' value='lettuce'>Add Lettuce</td>\n";
echo "<td><input type='checkbox' name='pickles' value='pickles'>Add Pickles</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='tomato' value='tomato'>Add Tomato</td>\n";
echo "<td><input type='checkbox' name='peppers' value='peppers'>Add Peppers</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='onion' value='onion'>Add Onion</td>\n";
echo "<td><input type='checkbox' name='olives' value='olives'>Add Olives</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='salt' value='salt'>Add Salt</td>\n";
echo "<td><input type='checkbox' name='suboil' value='suboil'>Add Sub Oil</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='pepper' value='pepper'>Add Pepper</td>\n";
echo "<td><input type='checkbox' name='avocado' value='avocado'>Add Avocado $0.50</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='sprouts' value='sprouts'>Add Sprouts $0.50</td>\n";
echo "</tr>\n";
####Extras####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Extra Meat or Cheese:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eroastbeef' value='eroastbeef'>Extra Roast Beef $1.00</td>\n";
echo "<td><input type='checkbox' name='eturkey' value='eturkey'>Extra Turkey $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eeverroastchicken' value='eeverroastchicken'>Extra EverRoast Chicken $1.00</td>\n";
echo "<td><input type='checkbox' name='eham' value='eham'>Extra Ham $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='esalami' value='esalami'>Extra Salami $1.00</td>\n";
echo "<td><input type='checkbox' name='epastrami' value='epastrami'>Extra Pastrami $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='etuna' value='etuna'>Extra Tuna $1.00</td>\n";
echo "<td><input type='checkbox' name='echickensalad' value='echickensalad'>Extra Chicken Salad $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='ebacon' value='ebacon'>Extra Bacon $1.00</td>\n";
echo "<td><input type='checkbox' name='eveggiepatty' value='eveggiepatty'>Extra Veggie Patty $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='evegetarian' value='evegetarian'>Extra Vegetarian $1.00</td>\n";
echo "<td><input type='checkbox' name='echeddar' value='echeddar'>Extra Cheddar $0.50</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eamerican' value='eamerican'>Extra American $0.50</td>\n";
echo "<td><input type='checkbox' name='eswiss' value='eswiss'>Extra Swiss Cheese $0.50</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eprovolone' value='eprovolone'>Extra Provolone Cheese $0.50</td>\n";
echo "<td><input type='checkbox' name='epepperjack' value='epepperjack'>Extra Pepper Jack Cheese $0.50</td>\n";
echo "</tr>\n";
echo "</table>\n";
####Name/Instructions####
echo "<b>Add your Name or Special Instructions</b><br>\n";
echo "<input type='text' name='instructions' value='' size='50'><br>\n";
echo "<input type='SUBMIT' name='SUBMIT' value='Add to Order'><br>\n";
echo "<input type='button' name='CANCEL' value='Cancel Item'>\n";
echo "</form>";
echo "</div>\n";
?>
I have also tried putting the entire form into a table, but that did not help either. Any suggestions would be great. I am fairly new to .php and html and so I do not even know where to start, in trouble shooting this issue.
Are you echoing the form into an html document? ie
<!doctype html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
YOUR FORM HERE
</body>
</html>
(http://www.w3schools.com/tags/tag_body.asp)
It's likely there is default styling on your div or on the html. In your css try:
html, body {
height: 100%;
width: 100%;
margin: 0;
}
div {
margin: 0;
}

php included form acting strangley with Firefox

For some reason when I call a function to create a form, the drop down menus aren't sticky and the browser forces users to click into the first text field and tab through the rest. It won't let them mouse through the fields. This is only happening in FF, not IE or Chrome. The forms I'm including are just basic html and only php pages I include are doing this.
Here is one function:
function addNoteUI($keyword) {
echo "<div id='search_result_right'>";
echo "<center><div id='enter_note_header'>Assign a Salesperson</div></center><p>";
echo "<form id='response' action='notes_add.php' method='post'>";
echo "<label for='mod_num'>MOD Initials: <label>";
echo "<input type='text' name='mod_num' size='2' maxlength='4'><p>";
echo "<label for='sales_num'>Assigned to Sales Person: <label>";
echo "<input type='text' name='sales_num' size='2' maxlength='4'><p>";
echo "<input type='hidden' name='question_num' value='$keyword'>";
echo "<label for='response'>Note</label><br>";
echo "<textarea name='response' cols='30' rows='7 maxlength='510'></textarea><p>";
echo "<input type='submit' value='Assign'>";
echo "</form>";
echo "</div>";
Here is the other:
function changeDept() {
include 'ask_search.php';
echo "<div id='search_result'>";
echo "<form action='change_dept.php' method='post'>";
echo "<label for='current_num'>Enter the Question Number to be Changed: <label>";
echo "<input type='text' name='current_num' size='4'><p>";
echo "<label for='store'>Select New Store/Department: <label>";
echo "<select name='store'>";
echo "<option>Please Select</option>";
echo "<option value='Albany'>Sales (Albany Store)</option>";
echo "<option value='Saratoga'>Sales (Saratoga Store)</option>";
echo "<option value='Web Sales'>Sales (TaftFurniture.com)</option>";
echo "<option value='Financing'>Financing</option>";
echo "<option value='Customer Service'>Customer Service</option>";
echo "<option value='Delivery'>Delivery</option>";
echo "<option value='HR'>Human Resources</option>";
echo "<option value='Web Contact'>Website Comment</option>";
echo "<input type='submit' value='Change' id='dropdown'>";
echo "</select></form></div>";
}
Thanks in advance.
Your labels are not closing properly:
echo "<label for='mod_num'>MOD Initials: <label>";
Should be:
echo "<label for='mod_num'>MOD Initials: </label>";
Also, in the second example, you have an input inside the select. The input must be outside:
echo "<option value='Web Contact'>Website Comment</option>";
echo "<input type='submit' value='Change' id='dropdown'>";
echo "</select></form></div>";
Should be:
echo "<option value='Web Contact'>Website Comment</option>";
echo "</select>";
echo "<input type='submit' value='Change' id='dropdown'></form></div>";
And another one, you're not closing your P tags:
echo "<input type='text' name='mod_num' size='2' maxlength='4'><p>";
Should be:
echo "<p><input type='text' name='mod_num' size='2' maxlength='4'></p>";
Try to be more careful with your tags. Some browsers are more forgiving about malformed HTML, but others are not.

Can we give function return in value field in hidden type field?

In hidden type text area can we give function in the value fileld.
Can anyone explain what does the following two lines do?
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVOAction\" VALUE=\"Authenticate()\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVORedirect\" VALUE=\"redirectwebsite.com\">\n";
Below is the full code.
echo "<HTML>\n";
echo "<HEAD>\n";
echo "<TITLE>Name</TITLE>\n";
echo "<META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
echo "<META NAME=\"pragma\" CONTENT=\"no-cache\">\n\n";
echo "</HEAD>\n";
echo "<BODY bgcolor=\"#FFFFFF\" text=\"#000000\" onLoad=\"javascript:document.nvoForm.submit();\">\n\n";
echo "<FORM NAME=\"nvoForm\" METHOD=\"POST\" ACTION="website.com">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVOAction\" VALUE=\"Authenticate()\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVORedirect\" VALUE=\"redirectwebsite.com\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVOTarget\" VALUE=\"_top\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nssaccount\" VALUE="account">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nssuser\" VALUE="user">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"nsspassword\" VALUE="pass">\n";
echo "</FORM>\n\n";
echo "</BODY>\n";
echo "</HTML>\n";
If I understand you correctly and your function return a string, you would be able to do:
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVOAction\" VALUE=\"".Authenticate()."\">\n";
Note:
As you can see with SO's code highlighting, you have a few lines that will probably break, because you don't escape your attribute quotations, like on this line for instance:
echo "<FORM NAME=\"nvoForm\" METHOD=\"POST\" ACTION="website.com">\n";
It needs to be:
echo "<FORM NAME=\"nvoForm\" METHOD=\"POST\" ACTION=\"website.com\">\n";
Update
I re-read your question, so here is an update of my answer.
// This line will (when fixed according to above) create an HTML form input,
// and give it the value of whatever is returned by the Authenticate() method
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVOAction\" VALUE=\"Authenticate()\">\n";
// This line will create an HTML form input and give it the
// value of redirectwebsite.com
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"NVORedirect\" VALUE=\"redirectwebsite.com\">\n";

Categories