If i had enter all value in say four input boxes with name prod[] and when i click on the submit button, i want to show each values without loosing it if the array values are isset.
<?php for($i=1; $i<=8; $i++) { ?> <tr>
<td style="width:50% !important;">
<input type="text" class="form-control" name="PprodName[]" />
</td>
#QaisarSatti
thanks bro but i think i just got the logic. here is my code :
<?php
$j = 0;
for($i = 1; $i<=8; $i++) {
?>
<tr>
<td style="width:50% !important;">
<input type="text" class="form-control" id="Ppr<?php echo $i; ?>" name="PprodName[]" value="<?php echo isset( $_POST['PprodName'][$j] ) ? $_POST['PprodName'][$j] : ''; ?>" />
</td>
</tr>
<?php $j++; } ?>
mark this checked if you found it useful. thanks !
$name = $_POST['PprodName'];
foreach( $name as $v ) {
echo $v;
}
Related
hope you are all doing well. I'm not too sure on how I worded the title so I'm sorry for that.
I have this code:
<form method="POST" action="checkoutManager.php" name="submitOrder">
<?php
if(isset($_SESSION["cart_item"])) {
$item_total = 0;
$total;
foreach ($_SESSION["cart_item"] as $item) {
$item_total += (($item["price"]-$item["discount"])*$item["quantity"]);
$total = $total + $item_total;
?>
<tr>
<td class="product-name">
<?php echo $item["name"]; ?> <strong class="product-qty"> × <?php echo $item["quantity"]; ?></strong>
</td>
<td class="product-total">
<span class="amount"><?php echo "$".$item_total; ?></span>
</td>
</tr>
<?php
$item_total = 0;
}
}
?>
<input type="submit" name="btnSubmitOrder" value="Submit Order">
</form>
How would I go about submitting all the $_SESSION items in using form tag. I have tried submitting as an array but failed. All help appreciated. Thanks in advance
why don't you create hidden elements like
<input type="hidden" name="total" value="<?php echo $total; ?>">
and anything you need use hidden input field and you can access them after the submit button is clicked by using $_POST in your checkoutManager.php
UPDATE
simply you can process all the fields in checkoutManager.php using session, you dont need any form to be submitted. create a link to checkoutManager.php and do all the calculations there
Try below code.
In this code I have added one hideen count field.
By using count u can use for loop after submit.
I display only one input for name but u can add multiple inputs inside for loop of form.
I also concated $i variables, so all input names are different as name1, name2,... U can use it on submit as $_POST['name'.$i] after submit.
<form method="POST" action="checkoutManager.php" name="submitOrder">
<?php
<input type="hidden" name="count" value="<?php echo count($_SESSION["cart_item"]); ?>">
$i=0;
foreach ($_SESSION["cart_item"] as $item)
{
?>
<input type="text" name="input_name<?php echo $i; ?>" value="<?php echo $item['name']; ?>" />
<?php
$i++;
}
?>
<input type="submit" name="btnSubmitOrder" value="Submit Order">
</form>
You need to add input fields in foreach loop for all your items that are coming in $_SESSION["cart_item"]. After submission, you need to use foreach again for inserting all your items in your temp table one by one.
Update your code like below:
<form method="POST" action="checkoutManager.php" name="submitOrder">
<?php
if(isset($_SESSION["cart_item"])) {
$item_total = 0;
$total = 0;
foreach ($_SESSION["cart_item"] as $item) {
$item_total +=
(($item["price"]-$item["discount"])*$item["quantity"]);
$total = $total + $item_total;
?>
<input type="hidden" name="price[]" value="<?php echo $item["price"]; ?>">
<input type="hidden" name="name[]" value="<?php echo $item["name"]; ?>">
<input type="hidden" name="discount[]" value="<?php echo
$item["discount"]; ?>">
<input type="hidden" name="quantity[]" value="<?php echo
$item["quantity"]; ?>">
<tr>
<td class="product-name">
<?php echo $item["name"]; ?> <strong class="product-qty"> × <?php
echo $item["quantity"]; ?></strong>
</td>
<td class="product-total">
<span class="amount"><?php echo "$".$item_total; ?></span>
</td>
</tr>
<?php
$item_total = 0;
}
}
?>
<input type="submit" name="btnSubmitOrder" value="Submit Order">
</form>
And you can access all your input fields after submission in the below way.
foreach($_POST['name'] as $key => $val){
echo $_POST['name'][$key];
echo $_POST['price'][$key];
echo $_POST['discount'][$key];
echo $_POST['quantity'][$key];
}
Hope it helps!
I need help on how to retain the entered values in the text fields where user entered the value after submit. I'm having difficulty trying to figure out how to retain the values, because when I click on the submit button, the page refreshes and then values gone, and I have to retype them again.
Below is my form:
<?php $count_name = count($x); ?>
<table>
<thead>
<tr>
<th colspan="<?php echo $count_name; ?>"><strong>MR</strong></th>
<th colspan="<?php echo $count_name; ?>"><strong>MS</strong></th>
</tr>
</thead>
<tbody>
<?php $_college = mysql_query("SELECT * FROM college");
if(mysql_num_rows($_college)) {
$i=0;
while($row_college=mysql_fetch_array($_college)) { ?>
<tr>
<?php for($j=0;$j<$count_name;$j++) { ?>
<td>
<input type="text" name="mr<?php echo $j; ?>[]" value=""/>
<td>
<?php } for($k=0;$k<$count_name;$k++) { ?>
<td>
<input type="text" name="ms<?php echo $k; ?>[]" value=""/>
<td>
<?php } ?>
</tr>
<?php } $i++;} ?>
</tbody>
<table>
<input type="hidden" value="<?php echo $count_name; ?>" name="totrows"/>
<input type="submit" value="Submit" name="submit"/>
Here's my code if button submit is click
<?php
if(isse($_POST['submit'])) {
$y = $_POST['totrows'];
$count_totcriteria = $y;
for($ab=0;$ab<$count_totcriteria;$ab++) {
$mr = 'mr_'.$ab;
$ms = 'ms_'.$ab;
$mr_score = $_POST[$mr];
$ms_score = $_POST[$mr];
foreach($mr_score as $key1 => $val1) {
if(is_numeric($val1) && !empty($val1)) {
$mr_val[] = $val1;
} else {
$msg = 'All fields are required and must be a valid score';
}
}
foreach($ms_score as $key2 => $val2) {
if(is_numeric($val2) && !empty($val2)) {
$ms_str[] = $val2;
} else {
$msg = 'All fields are required and must be a valid score';
}
}
}
}
I know I have to put some code in the 'value=""' in order to display back the entered values when form is submitted but I am not sure what code to use. Not sure how to catch each array values.
I think instead of
<input type="text" name="mr<?php echo $j; ?>[]" value=""/>
you are looking for something like this (assuming $i is your new outer loop)
<input type="text" name="mr_<?= $j ?>[<?= $i ?>]" value="<?= #$_POST['mr_'.$j][$i] ?>"/>
and the same change for the ms line.
Does that work?
I have several checkboxes, each representing individual team id. I have a few checkboxes above that each represent a group of those teams. I want to have the individual team checkboxes checked when that group is checked and visa versa. I am incredibly weak when it comes to javascript, and this might be basic but I cannot figure it out. My checkbox values are being pulled in php, and I am trying to avoid JQuery.
------------------PHP---Groups------------
<tr><th width="2%" class="thead1"></th><th class="thead1">Regions</th><th></th></tr>
<?php for ($i=0, $n=count( $this->regions111 ); $i < $n; $i++) {
$regions111 = $this->regions111[$i];?>
<tr><td><input type="checkbox" name="regionbox[]" value="<?php echo $regions111->id;?>"></td><td><?php echo $regions111->name;?></td></tr>
<?php }?>
--------------PHP-Individual Team ids---------------------------
<tr >
<th width="2%" class="thead1">
<input type="button" onclick="SetAllCheckBoxes('adminForm', 'teamarray2[]',true );" value="ALL" ><input type="button" onclick="SetAllCheckBoxes('adminForm', 'teamarray2[]',false );" value="None" > <th class="thead1">Teams
</th><th class="thead1">City</th>
</tr>
<?php
for ($i=0, $n=count( $this->rows ); $i < $n; $i++) {
$row = $this->rows[$i];
?>
<tr class="etblraw<?php echo $i % 2?>"><td>
<input type="checkbox" name="teamarray2[]" value="<?php echo $row->id;?>" <?php if (in_array("$row->id",$this->henry5)){echo 'checked="checked"';}else{}?> >
</td>
<td>
<?php
echo $row->t_name;
?>
</td>
<td>
<?php echo $row->t_city;?>
</td>
</tr>
--------------------End-PHP-----------------------------
----------------Javascript-select all function------------------
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
-----------------end Js------------------------------------------
I have the following code:
<form action="" method="POST">
<?php
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if($count > 11) $count = 11;
?>
<table>
<!-- Keeps track of the current number of rows -->
<input type="hidden" name="count" value="<?php echo $count+1; ?>"/>
<?php for($i = 0; $i < $count; $i++):
// Loop through all rows gathering the data here, and then creating the fields below
$val0 = isset($_POST['field'][$i]['0']) ? $_POST['field'][$i]['0'] : '';
$val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
$val2 = isset($_POST['field'][$i]['2']) ? $_POST['field'][$i]['2'] : '';
?>
<tr>
<td><input name="field[<?php echo $i; ?>][0]" value="<?php echo $val0; ?>"/></td>
<td><input name="field[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/></td>
<td><input name="field[<?php echo $i; ?>][2]" value="<?php echo $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
How can I make the fields into a dropdowns and when you press submit echo out the dropdown as text instead as a dropdown?
First: Fill in the following:
Make this to action="mytestpage.php"
Give this a name attribue like: name="send"
Give these fields types like: type="Text"
If you want a dropdown menu use <select> in combination with <option>...
Here is a start to learn how:
http://www.echoecho.com/htmlforms11.htm
To print your result do this:
if(isset($_POST['send'])
{
print($_POST['youroptionname']);
}
I hope it helped you.
I have the following code:
<form action="" method="POST">
<?php
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if($count > 11) $count = 11;
?>
<table>
<!-- Keeps track of the current number of rows -->
<input type="hidden" name="count" value="<?php echo $count+1; ?>"/>
<?php for($i = 0; $i < $count; $i++):
// Loop through all rows gathering the data here, and then creating the fields below
$val0 = isset($_POST['field'][$count]['0']) ? $_POST['field'][$count]['0'] : '';
$val1 = isset($_POST['field'][$count]['1']) ? $_POST['field'][$count]['1'] : '';
$val2 = isset($_POST['field'][$count]['2']) ? $_POST['field'][$count]['2'] : '';
?>
<tr>
<td><input name="field[<?php echo $count; ?>][0]" value="<?php $val0; ?>"/></td>
<td><input name="field[<?php echo $count; ?>][1]" value="<?php $val1; ?>"/></td>
<td><input name="field[<?php echo $count; ?>][2]" value="<?php $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
</form>
The problem is when I press submit it add 3 other fields but it clears the other fields. How can I keep the content from the fields but make them uneditable?
You are not echoing your values and your $count should be $i, as you'll end up with same field names
<form action="" method="POST">
<?php
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if($count > 11) $count = 11;
?>
<table>
<!-- Keeps track of the current number of rows -->
<input type="hidden" name="count" value="<?php echo $count+1; ?>"/>
<?php for($i = 0; $i < $count; $i++):
// Loop through all rows gathering the data here, and then creating the fields below
$val0 = isset($_POST['field'][$i]['0']) ? $_POST['field'][$i]['0'] : '';
$val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
$val2 = isset($_POST['field'][$i]['2']) ? $_POST['field'][$i]['2'] : '';
?>
<tr>
<td><input name="field[<?php echo $i; ?>][0]" value="<?php echo $val0; ?>"/></td>
<td><input name="field[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/></td>
<td><input name="field[<?php echo $i; ?>][2]" value="<?php echo $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
for($j=0;$j<3;$j++){
echo '<input type="hidden" name="field['.$i.'][0]" value="'.$_POST[field][$i][0].'" />';
}