I have this
<select name="method">
<?php
while($m = $sel->fetch(PDO::FETCH_ASSOC)){
echo '<option value="' . $m['type'] . '">' . $m['name'] . '</option>';
}
?>
</select>
And in the html form, in the source, it shows the type and name, and everything works, but when I submit the form, $_POST['method'] is blank, and var dumped is NULL. Would be great if someone could help.
Umm your data isn't inside of a form?
<form method="post">
<select name="method">
<?php
while($m = $sel->fetch(PDO::FETCH_ASSOC)){
echo '<option value="' . $m['type'] . '">' . $m['name'] . '</option>';
}
?>
</select>
</form>
<form name="input" action="your path" method="post">
<select name="method">
<?php
while($m = $sel->fetch(PDO::FETCH_ASSOC)){
echo '<option value="' . $m['type'] . '">' . $m['name'] . '</option>';
}
?>
</select>
</form>
Related
I try to add the required attribute to my select tag. Unfortunately this is simply ignored. The drop down list is filled dynamically from database entries. Does anyone know why? Is the dynamic elements to blame?
<div class="input-field col s12 m6 l6">
<?php
//-------------------------------------------//
$statement = $pdo->prepare("SELECT * FROM availableCards WHERE Active = '1' ORDER BY Description");
$statement->execute();
echo '<select name="images" id="images" required>';
echo '<option value="" disabled selected>Bitte wählen</option>';
while ($data = $statement->fetchAll(PDO::FETCH_ASSOC)) {
foreach ($data as $row) {
echo '<option name="' . $row['Value'] . '" value="' . $row['Value'] . '" data-icon="../cards/' . $row['ImagePath'] . '">' . $row['Description'] . '</option>';
}
}
echo '</select>';
//-------------------------------------------//
?>
<label for="images">Karte auswählen</label>
</div>
Copy and paste the below block. It's possible the form you have is not nested correctly.
<form action="/">
<div class="input-field col s12 m6 l6">
<?php
$data = array(
'1' => 'One',
'2' => 'Two',
'3' => 'Three',
);
//-------------------------------------------//
echo '<select name="images" id="images" required>';
echo '<option value="" disabled selected>Bitte wählen</option>';
foreach ($data as $row) {
echo '<option name="' . $row['Value'] . '" value="' . $row['Value'] . '" data-icon="../cards/' . $row['ImagePath'] . '">' . $row['Description'] . '</option>';
}
echo '</select>';
//-------------------------------------------//
?>
<label for="images">Karte auswählen</label>
<button type="submit" name="button">Bestätigen</button>
</div>
</form>
Please add the closing form tag and the of the last div. StackOverflow's embed code is a nightmare.
Actually, what happening is at your HTML value="" is not printing in
<option disabled selected>Bitte auswählen</option>
But in your code you have already added
echo '<option value="" disabled selected>Bitte wählen</option>';
If you just focus on that why it is not showing value="" in option tag then it will work fine.
I am trying to retrieve data field from a database and store them in a dropdown box so that they correlate to each other which i have done but when I put them into a dropdown box they appear but with no spaces between them and I want the words separated.
Any help much appreciated.
<form name="FrmAmend" method="post" action="amenddvd2.php">
Select from the list below<br>
<select name="Film" t[enter link description here][1]itle="Select DVD">
<option value="" selected disabled>Select DVD</option>
<?php
$result = mysqli_query($con, "SELECT `DVD ID`, `Title`, `Certificate` FROM tbldvd;");
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['DVD ID'] . $row['Title'] . $row['Certificate'] . "'>" . $row['DVD ID'] . $row['Title'] . $row['Certificate'] . "</option>";
}
?>
</select><br>
<a href="menu.php"</a>Return To Main Menu<br>
<input type="submit" name="Submit" value="Select DVD">
</a>
</form>
It will be better you do it this way
<form name="FrmAmend" method="post" action="amenddvd2.php">
Select from the list below<br>
<select name="Film" t[enter link description here][1]itle="Select DVD">
<option value="" selected disabled>Select DVD</option>
<?php
$result = mysqli_query($con, "SELECT `DVD ID`, `Title`, `Certificate` FROM tbldvd;");
while ($row = mysqli_fetch_assoc($result)) {
?>
<option value=' <?php echo"$row['DVD ID'] $row['Title'] $row['Certificate']" ?> ' selected disabled>Select DVD</option>
<?php
}
?>
</select><br>
<a href="menu.php"</a>Return To Main Menu<br>
<input type="submit" name="Submit" value="Select DVD">
</a>
</form>
concat a space between the vars
echo "<option value='" . $row['DVD ID'] . $row['Title'] . $row['Certificate'] . "'>" . $row['DVD ID'] . ' ' . $row['Title'] . ' ' . $row['Certificate'] . "</option>";
In a form after submitting the data, if i want to edit form the data in the form should be from database i have to echo the selected value from the database if data is present else it has to show the options to select the values from another table where these options are present
here is the code
please correct it
<select name="ccname" class="form-control form-color">
<?php
if(isset($storyData)) {
echo '<option value="' . $storyData['ccname'] . '">' . $storyData['ccname'] . '</option>';
}
else{
echo "<option value="">CCname</option>";
foreach(getNames() as $ccname)
echo '<option value="'.$ccname.'">'.$ccname.'</option>';
}
?>
</select>
after working with concatenation operator finally debugged the code
here is the code
that i corrected
<select name="ccname" class="form-control form-color">
``<?php if(isset($storyData))
{
echo "<option value = '" . $storyData['ccname'] . "'>".$storyData['ccname']."</option>";
}
else{
echo "<option value='1'>CCname</option>";
foreach(getNames() as $ccname)
echo '<option value="'.$ccname.'">'.$ccname.'
</option>';
}
?>
</select>
I have a gender array as an example, but I am also using longer select list such as states. I want to capture the option value in a PHP varible that the client side user chooses. Then I can use that captured value in an email message.
function genderList() {
$gender = array('M'=>"Male",'F'=>"Female",);
return $gender;
}
$gender = genderList();
$email_form = '<?php $states = statesList(); ?>
<form class="aw-contact-form" method="post" action="' . get_permalink() . '">
<label for="cf_gender">' . $label_gender . '</label>
<select name="gender" id="cf_gender">
<option selected="selected"></option>';
foreach ($gender as $key => $value) {
$email_form .= '<option value="' . $key . '">' . $value . '</option>';
}
$email_form .= '</select>
</form>
return $email_form;
Any help will be greatly appreciated.
I need to retain the dropdown list value after post submit where the values for the dropdown list are read populated from an array, not hardcoded.
This is my code for populating the dropdown list:
<?php
foreach ($catalogueArray as $cataloguePDFName) {
echo '<option value="'. $cataloguePDFName . '">' . $cataloguePDFName . '<option />';
}
?>
<label>Template</label>
<select name="templatepdfs" />
<?php
foreach ($templateArray as $templatePDFName) {
echo '<option value="'. $templatePDFName . '">' . $templatePDFName . '<option />';
}
?>
<input type="submit" name="submit" value="Submit">
Can somebody guide me how can I echo the selected dropdown value. I have seen examples how it can be done when the values are hardcoded, but for some reason im running into errors when trying for my dynamic dropdown list. Any help would be appreciated.
Thanks
Did you mean something like this?
Put your code in :
if(array_key_exists('submit' , $_POST))
{
echo $_POST['templatepdfs'];
}
else
{
?>
<form method='post' action=''>
<--Your code here-->
</form>
<?php
}
OR:
<form method='post' action=''>
<label>Template</label>
<select name="templatepdfs" />
<?php
foreach ($templateArray as $templatePDFName) {
echo '<option value="'. $templatePDFName . '"';
if($templatePDFName == $_POST['templatepdfs']) echo ' SELECTED';
echo '>' . $templatePDFName . '<option />';
}
?>
<input type="submit" name="submit" value="Submit">
</form>