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);
}
Related
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 trying to create a form where I need to allow user to select different values (from select tag) against some labels.
I have two different array in php.
the standard array that contains the labels for select.
a set of values to be selected against the labels.
My problem is when I press the submit button, the form is submitted but $_POST does not show any value selected by the select tag. I want to get the selected values against the labels.
here is my code:
<?php
$data = array ('name', 'phone', 'address');
$values = array('a','2344','xyz');
?>
<html>
<head></head>
<body>
<form action="<?php $_SERVER["PHP_SELF"] ?>" method="post">
<?php for($i = 0; $i < count($data); $i++){ ?>
<label for='<?php $data[$i]?>'> <?php echo $data[$i]?></label>
<select name='<?php $data[$i]?>' id = '<?php $data[$i]?>'>
<?php foreach($values as $val){ ?>
<option value='<?php $val ?>'> <?php echo $val ?> </option>
<?php } ?>
</select>
<?php } ?>
<button type="submit" name="submit" value="submit">Submit</button>
<br>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
echo$_POST['name'];
}
?>
When I press the submit button the error I get is "Notice: Undefined index: name". I have extensively searched in the questions already posted about multiple select statements but none of the answers matched my criteria. Thanks for the help.
You are forgot to print variables
<html>
<head></head>
<body>
<form action="<?php $_SERVER["PHP_SELF"] ?>" method="post">
<?php for($i = 0; $i < count($data); $i++){ ?>
<label for='<?php echo $data[$i]?>'> <?php echo $data[$i]?></label>
<select name='<?php echo $data[$i]?>' id = '<?php echo $data[$i]?>'>
<?php foreach($values as $val){ ?>
<option value='<?php echo $val ?>'> <?php echo $val ?> </option>
<?php } ?>
</select>
<?php } ?>
<button type="submit" name="submit" value="submit">Submit</button>
<br>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
echo$_POST['name'];
}
?>
You have not written echo before each variable in selectbox:
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<?php for($i = 0; $i < count($data); $i++) { ?>
<label for='<?php echo $data[$i]; ?>'> <?php echo $data[$i]?></label>
<select name='<?php echo $data[$i]; ?>' id = '<?php echo $data[$i]; ?>'>
<?php foreach($values as $val){ ?>
<option value='<?php echo $val; ?>'> <?php echo $val ?> </option>
<?php } ?>
</select>
<?php } ?>
<button type="submit" name="submit" value="submit">Submit</button>
</form>
My Code I want to single checked. but It is multiple check . How can i single selection in this types of situation ?
This is my code
<?php
$i=5;
for($i=1; $i<6; $i++)
{
?>
<form name="form" id="myform" class="frmclass">
<input type="radio" name="rdo" value="<?php echo $i; ?>"> <?php echo $i; ?> <br>
</form>
<?php }
?>
You have created 5 seperate forms. Place the <form> and </form> tags outside the loop
<?php
$i=5;
?>
<form name="form" id="myform" class="frmclass">
<?php
for($i=1; $i<6; $i++) {
{
?>
<input type="radio" name="rdo" value="<?php echo $i; ?>"> <?php echo $i; ?> <br>
<?php
}
?>
</form>
Just place your form outside of loop. like below..
<form name="form" id="myform" class="frmclass">
<?php
$i=5;
for($i=1; $i<6; $i++)
{
?>
<input type="radio" name="rdo" value="<?php echo $i; ?>"> <?php echo $i; ?> <br>
<?php
}
?>
</form>
I have following code (it's piece of bigger code):
<?php
include_once 'init/init.funcs.php';
$x = $_SESSION['answering']['index'];
echo $_SESSION['answering']['questions'][$x-1];
$result4 = mysql_query('SELECT kysimus_id FROM katse_kysimused
where kysimus= "' .$_SESSION['answering']['questions'][$x] . '"');
$question_id = mysql_result($result4, 0);
$result5 = mysql_query('SELECT * from katse_valik_vastused
where kysimus_id="'. $question_id . '"');
if($result5 === FALSE) {
die(mysql_error());
}
while($row = mysql_fetch_assoc($result5)) {
$options[] = $row['vasuts'];
}
//foreach($options as $option=>$option_value) {
//echo $option_value;
$count=count($options);
?>
<html>
<br>
<form method="post" action="answering.php">
<input type="radio" name="1"><?php echo $options[0]?><br>
<input type="radio" name="2"><?php echo $options[1]?><br>
<input name= "submit" type="submit" value="Vasta">
</form>
</html>
Right now there are two fixed radio buttons. But I want it to have as many buttons, as many elements are in array "options" and each of them to have a value of one element written next to it. How could I do it?
Use a for loop for this: http://www.php.net/manual/en/control-structures.for.php
for ($i = 1; $i < count($options); $i++) {
?>
<input type="radio" name="<?php echo $i; ?>"><?php echo $options[$i]?><br>
<?php
}
Try like this:
<?php
while($row = mysql_fetch_assoc($result5)) {
$options[] = $row['vasuts'];
}
?>
<html>
<br>
<form method="post" action="answering.php">
<?php
foreach($options as $option=>$option_value) {
?>
<input type="radio" name="<?= $option; ?>"><?php echo $option_value?><br>
<?php }?>
<input name= "submit" type="submit" value="Vasta">
</form>
<html>
<br>
<form method="post" action="answering.php">
<?php
foreach ($options as $index=>$option) {
echo "<input type='radio' name='{$index}'>{$option}<br>";
}
?>
<input name= "submit" type="submit" value="Vasta">
</form>
</html>
Try using the below code.
<html>
<br>
<form method="post" action="answering.php">
<?php
foreach ($options as $key => $value) {
?>
<input type="radio" name="<?php echo $key; ?>"><?php echo $options[$key] ?><br>
<?php
}
?>
<input name= "submit" type="submit" value="Vasta">
</form>
</html>
you can do this using for each, like this:
<form method="post" action="answering.php">
<?php foreach ($options as $key => $value): ?>
<input type="radio" name="<?php echo $key; ?>" /><?php echo $value; ?><br />
<?php endforeach; ?>
<input name= "submit" type="submit" value="Vasta">
</form>
<form action="" method="post">
<?php
$i=0;
while(i<4){ ?>
<input type="checkbox" name="<?php echo 'chkApprove_'.$i; ?>"/>
<?php
}
?>
<input type="submit" name="btnsubmit"/>
</form>
if(isset($_POST['btnsubmit']))
{
$i=0;
while($i<4)
{
echo $i;
$chek=$_POST['chkApprove_'.$i];// Error Undefined Index
$i++;
}
}
Error is displayed as Undefined index: chkApprove_0...chkApprove_3. Am i doing something wrong here.
$ was missing in you while loop before "i". and $i was not increamenting.
<?php
$i=0;
while($i<4){ ?>
<input type="checkbox" name="<?php echo 'chkApprove_'.$i; ?>"/>
<?php
$i++;
}
?>
try this : you start from $i=0 but not increment $i++.
<form action="" method="post">
<?php
$i=0;
while($i < 4)
{
?>
<input type="checkbox" name="<?php echo 'chkApprove_'.$i; ?>"/>
<?php
$i++;
}
?>
<input type="submit" name="btnsubmit"/>
</form>
<?php
if(isset($_POST['btnsubmit']))
{
$i=0;
while($i < 4) {
echo $i;
$chek=$_POST['chkApprove_'.$i];// Error Undefined Index
$i++;
}
}
?>
well you have a syntax error and you forget to increment $i in this loop:
$i=0;
while(i<4){ ?>
<input type="checkbox" name="<?php echo 'chkApprove_'.$i; ?>"/>
<?php
}
should be
$i=0;
while($i<4){ ?>
<input type="checkbox" name="<?php echo 'chkApprove_'.$i; ?>"/>
<?php
$i++;
}
Because you don't increment $i in the intial loop, but in the latter looop you do, you get the undefined index
Your corrected code:
<form action="" method="post">
<?php
$i=0;
while($i<4){
?>
<input type="checkbox" name="<?php echo 'chkApprove_' . $i; ?>"/>
<?php
$i++;
}
?>
<input type="submit" name="btnsubmit"/>
</form>
<?php
if (isset($_POST['btnsubmit'])) {
$i = 0;
while ($i < 4) {
echo $i;
$chek = $_POST['chkApprove_' . $i];
// Error Undefined Index
$i++;
}
}