I have a field set and inside it i have a form . it does not work . i mean to say . when i see the tags using firebug , the form tags will not be there at all..how do u i get over it.
this is how the code goes...its a php code..
<div id="dialog-form_surg_couns" title=" Surgical Counselling">
<?php
$surgCount = 0;
foreach($this->surgery as $surgery) {
$surgCount++;
$newId = str_replace(' ','',$surgery->getSurgeryname());
?>
<div class='fieldreq1Pct'>
<div class='fieldItemLabel'>
<label for=''><?php echo $surgery->getSurgeryname() ?></label>
</div>
<div class='fieldItemValue'>
<input type='checkbox' class='surg_couns_tests' id="<?php echo $newId ?>" name='surg_couns_tests' value="<?php echo $surgery->getSurgeryname() ?>" <?php echo (($showValue && strstr($visitRecord->getSurgcounstests(),$surgery->getSurgeryname())) ? 'checked' : "" ); ?> onClick="javascript:showBlock(this.id);">
</div>
</div>
<?php
if(($surgCount % 3) == 0)
{
?>
<div class='clear'></div>
<?php
}
}
?>
<div class='clear'></div>
<hr/>
<?php
foreach($this->surgery as $surgery) {
$newId = str_replace(' ','',$surgery->getSurgeryname());
$fieldCount = 0;
?>
<div id='<?php echo $newId ?>_block' style='display:none;' class='check_block'>
<form method='POST' action ='' id ='<?php echo $newId ?>_form'>
<table border='0' class='surg_table'>
<?php
foreach($this->surgeryTemplate as $surgerytemplate) {
if($surgery->getSurgeryid() == $surgerytemplate->getSurgeryid())
{
$fieldCount++;
$fieldName = 'field'.$fieldCount;
$fieldId = $surgerytemplate->getFieldid();
if($surgerytemplate->getRequired() == 'Y')
{
$required = 'required';
}
else
{
$required = '';
}
if($surgerytemplate->getType() == 'AN')
{
$validation = 'alpha';
}
else
{
$validation = '';
}
?>
<tr>
<td>
<?php echo $surgerytemplate->getFieldname(); ?>
</td>
<td>
<?php
if($surgerytemplate->getType() == 'B')
{
echo '<input type=\'radio\' name=\''.$fieldName.'\' value=\'Yes\'>Yes';
echo '<input type=\'radio\' name=\''.$fieldName.'\' value=\'No\'>No';
}
else
{
echo '<input type=\'text\' name=\''.$fieldName.'\' id=\''.$fieldName.'\' class=\''.$required.' '.$validation.'\' onblur="checkValid(this.id)"><div id=\''.$fieldName.'error\'></div>';
}
?>
</td>
</tr>
<?php
}
}
?>
</table>
<center><input type='button' name='submit' value='submit' onclick='javascript:submitSurgeryForm("<?php echo $newId ?>")'></center>
</form>
</div>
<?php
}
?>
</div>
You can't have a form tag inside another form. The following HTML is invalid:
<form>
<fieldset>
<form>
<input>
</form>
</fieldset>
</form>
The browser will silently ignore the second form, and instead will interpret your page as:
<form>
<fieldset>
<input>
</fieldset>
</form>
Related
I've search the forum for the same situation that I have but still couldn't find the solution. It's probably a piece of cake but I can't figure it out why my $_GET[] doesn't work.
I've created a product page and when I add something to the cart I want to display a message. I've made it work with the url in the form action but then my cart counter in the header stops working properly.
If it's possible I don't want to add any extra in the url like a "?success" because then it just keeps adding ?success to the url if I add more to the cart, that works in action but not with header() ?
Here is my code for the product page:
<?php include_once '../header.php';
$message = "";
$product = New Product;
$cart_data = [];
// if the variables are set - run the following statement
if(isset($_POST["addtocart"])) {
if(isset($_COOKIE["cart"])) {
// Removes backlashes and dont replace previous item, gives every item a new row.
$cookie_data = stripslashes($_COOKIE['cart']);
$cart_data = json_decode($cookie_data, true);
}
// Returns the productid and Size in the array
$item_list = array_column($cart_data, 'ProductsId');
$size_list = array_column($cart_data, 'Size');
// Returns the value if the statement is true
if(in_array($_POST["ProductsId"], $item_list) && in_array($_POST['selectedSize'], $size_list)) {
// A foreachloop that repeats the array value of the selected key variable.
foreach($cart_data as $keys => $values) {
if($cart_data[$keys]["ProductsId"] == $_POST["ProductsId"] && $cart_data[$keys]["Size"] == $_POST["selectedSize"]) {
$cart_data[$keys]["quantity"] = $cart_data[$keys]["quantity"] + $_POST["quantity"];
}
}
}
else {
$item_array = array(
'Img' => $Img = filter_var($_POST["Img"], FILTER_SANITIZE_STRING),
'ProductName' => $ProductName = filter_var($_POST["ProductName"], FILTER_SANITIZE_STRING),
'Size' => $Size = filter_var($_POST['selectedSize'], FILTER_SANITIZE_STRING),
'ProductsId' => $ProductsId = filter_var($_POST["ProductsId"], FILTER_SANITIZE_NUMBER_INT),
'Price' => $Price = filter_var($_POST["Price"], FILTER_SANITIZE_NUMBER_INT),
'quantity' => $quantity = filter_var($_POST["quantity"], FILTER_SANITIZE_NUMBER_INT),
);
$cart_data[] = $item_array;
}
$item_data = json_encode($cart_data);
setcookie('cart', $item_data, time() +(3600),'/');
header("location: product-detail.php?product=".$_GET['product']."?success");
}
if(isset($_GET['success'])) {
$message = "Varan lades till i varukorgen";
};
var_dump($message);
?>
<main id="product-content">
<section>
<form method="post" name="cartCount" action="">
<!-- product-detail.php?product=<?php echo $_GET['product']; ?> -->
<?php if(isset($_GET['product'])) {
$product->ProductsId = $_GET['product'];
$product->ProductId = $_GET['product'];
$product->ProductsId = $_GET['product'];
} else {
$product->ProductsId = $_POST['ProductsId'];
}
$result = $product->get_product();
$test = $product->get_productvariation();
while ($row = $result->fetch()) { ?>
<div class="product-card-detail">
<div class="product-image-wrapper">
<img class="product-image" src="../<?php echo $row['Img'];?>" >
<input type ="hidden" name="Img" value="<?php echo $row['Img'] ?>">
<?php $results = $product->get_images();
$Images = $results->fetch();
if(isset($Images['Image'])) { ?>
<img class="product-image" src="../<?php echo $Images['Image'];?>">
<?php } ?>
</div>
<div class="product-details-text">
<h2 class="title"><?php echo $row['ProductName']; ?></h2>
<input type ="hidden" name="ProductName" value="<?php echo $row['ProductName'] ?>">
<span class="price"><?php echo $row['Price'];?> SEK</span>
<input type ="hidden" name="Price" value="<?php echo $row['Price'] ?>">
<span class="select-title">Storlek</span>
<select class="size" name="selectedSize">
<?php while ($sizeRow = $test->fetch()) { ?>
<option>
<?php echo $sizeRow['Size']; ?>
</option>
<?php } ?>
</select>
<input type="hidden" name="quantity" value="1" />
<input type="submit" class="addtocart-btn" name="addtocart" value="Lägg i varukorgen"/>
<div><?php echo $message ?></div>
<input type ="hidden" name="ProductsId" value="<?php echo $row['ProductsId'] ?>">
<span class="title-description">Beskrivning</span>
<p class="description"><?php echo $row['Description']; ?></p>
</div>
</div>
<?php } ?>
</form>
</section>
</main>
<?php include_once "../footer.php";?>
I've made a test page that works exactly as expected so I can only think that is has to be something about the url?
Test code:
<?php
$message ="";
if(isset($_POST['submit'])) {
header("location: index.php?success");
}
if(isset($_GET['success'])) {
$message = "hello";
}
var_dump($message);
?>
<form method="post" action="">
<input text name="name" value="">
<input type="submit" name="submit" value="submit">
<?php echo $message ?>
</form>
Glad if anyone can see why it doesn't work!
You have made a mistake:
header("location: product-detail.php?product=".$_GET['product']."?success");
See the above line and notice that you are appending param success with ?.
Make it & as:
header("location: product-detail.php?product=".$_GET['product']."&success");
How to make that at the push of a button
"<input type ='submit' name='delete' value='Delete messages'>"
deleted messages selected by a checkbox? All messages and checkboxes appear through the counter "for" as messages are received. What im doing wrong? I think i have mistake with foreach and form action. Please, help me
my code is:
<php function display_list($auth_user, $accountid, $messageid, $fullheaders) {
if(!$accountid) {
echo "<p style=\"padding-bottom: 100px\">No mailbox selected.</p>";
} else {
$imap = open_mailbox($auth_user, $accountid);
if($imap) {
$headers = imap_headers($imap);
$messages = count($headers); ?>
<div class="view-mailbox-block">
<div class="new-message">
<form action="index.php?action=new-message" method="post">
<input type ='submit' value='Write a letter'>
</form>
</div>
<form action="" method="post">
<input type ='submit' name='delete' value='Delete messages'>
</form>
</div>
<div class="incoming-sent-messages-mail">
<p>Почта</p>
</div>
<div class="incoming-sent-messages">
<div class="incoming-sent-messages-p">
<p>
<?php echo "<a href='index.php?action=view-mailbox'>"; ?> View </a>
</p>
<p>
<?php echo "<a href='index.php?action=view-mailbox-sent'>"; ?> Sent </a>
</p>
</div>
</div>
<div>
<div class="senders overflow">
<form class="sender-checkbxes">
<?php echo '<input type="checkbox" name="deleteall" value="checkbox-all">'; ?>
<?php for ($i = 0; $i < $messages; $i++) {
echo "<div><div>";
echo '<input type="checkbox" name="delete[]" value="<?php echo $delete ?>">';
echo "</form>";
echo "</div></div>\n";
} ?>
<form action='index.php?action=delete&messageid='<?php echo $check;?>'>
<?php if(!empty($_POST['delete'])) {
foreach($_POST['delete'] as $check) {
imap_delete($imap, $check);
imap_expunge($imap);
imap_close($imap);
return true;
}
} ?>
</form>
</div>
I am currently creating a basic CMS for practice purposes and I can't seem to figure out:
How to Update all fields at once AND delete (or upload new) images for each independent record
Any help would be appreciated :)
Updating All Fields Code:
if (isset($_POST['submit'])) {
$id = $_POST['id'];
$sql = "UPDATE services SET page_title=:pageTitle, event_title=:eventTitle, event_content=:eventContent WHERE id=:id";
foreach ($id as $key => $value) {
$query = $connect->prepare($sql);
$query->bindValue(':pageTitle', $_POST['page_title'], PDO::PARAM_STR);
$query->bindValue(':eventTitle', $_POST['event_title'][$key], PDO::PARAM_STR);
$query->bindValue(':eventContent', $_POST['event_content'][$key], PDO::PARAM_STR);
$query->bindValue(':id', $id[$key], PDO::PARAM_STR);
if ($query->execute()) {
$message = 'Records updated.';
} else {
$message = "Failed to update records. Please contact Administrator.";
}
}
}
PHP/HTML Code:
<form method="post" action="">
<?php
$sql = "SELECT * FROM services";
$query = $connect->prepare($sql);
$query->execute();
$i = 1;
while($results = $query->fetch(PDO::FETCH_ASSOC)) { ?>
<?php if ($i === 1) { ?>
<input type="text" value="<?php echo $results['page_title'] ?>" name="page_title">
<?php } ?>
<div class="service">
<input type="hidden" value="<?php echo $results['id'] ?>" name="id[]">
<input type="text" value="<?php echo $results['event_title'] ?>" name="event_title[]"/>
<?php
if ($results['event_imgSrc'] == '') { ?>
<img src='' style="width:100px; height:100px;">
<?php } else { ?>
<img src="<?php echo '../'.$results['event_imgSrc'] ?>" name="event_imgSrc">
<?php }
?>
<input type="file" name="image">
<input type="submit" name="del_img" value="Delete Image">
<input type="submit" name="upload_new" value="Upload New Image">
<textarea name="event_content[]"><?php echo $results['event_content'] ?></textarea>
</div>
<?php $i++; } ?>
<input type="submit" name="submit" value="Update"/>
<?php if (isset($message)) { ?>
<p><?php echo $message ?></p>
<?php } ?>
</form>
I'm trying to edit my selections using checkbox method, the values which are previously in database are checked while the other's are not. What I'm trying to do is check other checkbox or uncheck the previous selected check box but when i submit my edition nothing got happen because It is not getting values from the checkboxes I don't know why. Here is my Code. Thank you
<?php
if(isset($_GET['Institute_Code']))
{
$Institute_Code=$_GET['Institute_Code'];
$getselect=mysqli_query($con,"SELECT radio FROM institute WHERE Institute_Code='$Institute_Code'");
while($row=mysqli_fetch_array($getselect))
{ $Degree_Programs = $row ['radio'];
}}
?>
<form action="#" method="post" name="add_Institute">
<div class="container">
<!--add here-->
<?php
$char="";
$name[]="";
$j=0;
$dbvalue="";
if($Degree_Programs!=NULL )
{
$Degree_ProgramStrlen=Strlen($Degree_Programs);
for ($i=0; $i<=$Degree_ProgramStrlen; $i++)
{
$char = substr( $Degree_Programs, $i, 1 );
if($char == ',')
{
//echo $name[$j];
//$name="";
$j=$j+1;
$name[$j]="";
}
else
{
$name[$j] .= $char;
}
}
}
else
{} ?>
<!--" >-->
<div class="row col-md-offset-1">
<div class="col-md-9 ">
<?php echo "<b>Degree Programs</b>"; ?>
<br>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Matric Arts')
$dbvalue=$name[$i];
} ?>
<label>Matric Arts</label>
<input type="checkbox" name="check_DegreePrograms[]" value="Matric Arts" <?php
$value="Matric Arts";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Matric Science')
$dbvalue=$name[$i];
} ?>
<label for="tag_2">Matric Science</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_2" value="Matric Science" <?php
$value="Matric Science";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='FSc. Pre-Engineering')
$dbvalue=$name[$i];
} ?>
<label for="tag_3">FSc. Pre-Engineering</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_3" value="FSc. Pre-Engineering" <?php
$value="FSc. Pre-Engineering";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Fsc. Pre-Medical')
$dbvalue=$name[$i];
} ?>
<label for="tag_4">FSc. Pre-Medical</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_4" value="FSc. Pre-Medical"<?php
$value="FSc. Pre-Medical";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='I.com')
$dbvalue=$name[$i];
} ?>
</div>
</div>
<input type="Submit" name="Submit" value="Submit" class="btn btn-success pull-right"/>
</form>
</div>
<?php //} }
$pets ="";
$flag =0;
if(isset($_GET['Institute_Code']))
{
$Institute_Code=$_GET['Institute_Code'];
if (isset($_POST['Submit'])) {
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['check_DegreePrograms'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_DegreePrograms'] as $selected){
$pets .= $selected . ",";
$flag = 1;
}
}
}
if ($flag == 1) {
$pets = rtrim($pets);
}
$updated = mysqli_query($con ,"UPDATE institute set radio='$pets' where Institute_Code=1233");
if($updated)
{
echo "Data successfully updated...";
}
else {
die('Could not update data: ' . mysql_error());
}
}
}
?>
<?php
include 'footer.php';
?>'
Here is my code
<?php
if(isset($_POST['type'])){
if (is_array($_POST['type'])) {
echo "IS ARRAY!!!!!!!!";
}
else {
echo "IS NOT ARRAY!!!";
}
}
?>
and..
<div id="player" class="group">
<form action=<?php echo $_SERVER['SCRIPT_NAME']; ?> id="playerform" method="post">
<?php
for($j = 0; $j < sizeof($_SESSION['playercharacter']->defendAgainst); $j++) {
?>
<input type="checkbox" name="type[]" value=<?php echo $_SESSION['playercharacter']->
defendAgainst[$j]; ?> />
<?php
}
?>
</form>
</div>
Thing is....$_POST['type'] is just a single value rather than an array.. How do i get ALL checked values? Thanks for your time...
I hope it will help you
<form action="" method="post" >
<?php
for($i=0;$i<10;$i++){
echo '<input type="checkbox" name="type[]" value="'.$i.'">'.$i.'<br/>';
}
?>
<input type="submit" name="submit" >
</form>
if(isset($_POST['submit'])){
$arr=array();
foreach($_POST['type'] as $key=>$value)
{
$arr[$key]=$value;
}
var_dump($arr);
}