Getting All $_Post from Multiple Select Value

Getting All $_POST From Multiple Select Value

I've found the answer...

<select name="cars[]" multiple="multiple">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>

and in the PHP part :

$cars = $_POST['cars'];
print_r ($cars);

Post values from a multiple select

You need to add a name attribute.

Since this is a multiple select, at the HTTP level, the client just sends multiple name/value pairs with the same name, you can observe this yourself if you use a form with method="GET": someurl?something=1&something=2&something=3.

In the case of PHP, Ruby, and some other library/frameworks out there, you would need to add square braces ([]) at the end of the name. The frameworks will parse that string and wil present it in some easy to use format, like an array.

Apart from manually parsing the request there's no language/framework/library-agnostic way of accessing multiple values, because they all have different APIs

For PHP you can use:

<select name="something[]" id="inscompSelected" multiple="multiple" class="lstSelected">

How to get all selected values from multiple select option?

Use name as like problems[] instead of problems

//Simple Form and getting the values

<form name="s" method="post" action="" >
<select multiple="multiple" name='problems[]' id='problems' class="inpBox multiple" size='50' style="height:150px;" >
<option value="Cannot Copy">Cannot Copy</option>
<option value="Cannot Print">Cannot Print</option>
<option value="Cannot Print">Cannot Scan</option>
<option value="Cannot Fax">Cannot Fax</option>
<option value="Lines Appear When Printing/Copying">Lines Appear When Printing/Copying</option>
<option value="Scan to Email Failed">Scan to Email Failed</option>
<option value="Toner Low/Empty">Toner Low/Empty</option>
<option value="Others">Others</option>
</select>
<input type="submit" name="submit" value="submit" />
</form>

<?php
if (isset($_POST['submit'])) {
$problems = implode(',', $_POST['problems']);
echo $problems;
}
?>

How to get all selected values of a multiple select box?

No jQuery:

// Return an array of the selected opion values
// select is an HTML select element
function getSelectValues(select) {
var result = [];
var options = select && select.options;
var opt;

for (var i=0, iLen=options.length; i<iLen; i++) {
opt = options[i];

if (opt.selected) {
result.push(opt.value || opt.text);
}
}
return result;
}

Quick example:

<select multiple>
<option>opt 1 text
<option value="opt 2 value">opt 2 text
</select>
<button onclick="
var el = document.getElementsByTagName('select')[0];
alert(getSelectValues(el));
">Show selected values</button>

Get Multiple name value of multiple select in PHP POST

It is not very clear what you are trying to obtain. My best guess is that you want to link the first mailwizz_domain text input to the first redirect_url_variables select and the second mailwizz_domain to the second redirect_url_variables.

This is not happening because redirect_url_variables collects the values from both selects in a single array (that may even be empty if no option is selected).

So, redirect_url_variables should be a bidimensional array, where the first index is linked to the relative mailwizz_domain index.

For example:

<!-- First input -->
<input type="text" name="mailwizz_domain[1]">
...
<select multiple="multiple" name="redirect_url_variables[1][]">...
...

...
<!-- Second input -->
<input type="text" name="mailwizz_domain[2]">
...
<select multiple="multiple" name="redirect_url_variables[2][]">...
...

Get All Value Of Multiple Select And Display Automatically Without Choosing Value

change the name to test[] for multi select

 <select name="test[]" id="sbTwo" multiple="multiple" class="form-control">

Can't get the values from multiple select with $_GET request

try with as below it might be simple

 if (( isset($_GET['location']) && !empty($_GET['location']) )) {
die(var_dump($_GET['location'])); // the var_dump doesn't return an array at all
//$loc = implode(', ', $_GET['location']);
$_GET['location'] = array('first'=>'loc1','second'=>'loc2','third'=>'loc3');
$loc = implode('","', $_GET['location']);
$loc ='"'.$loc.'"';

$sql='SELECT * FROM locations WHERE AreaID IN ('.$loc.')';
echo $sql;
}

result query

SELECT * FROM locations WHERE AreaID IN ("loc1","loc2","loc3")

How to get multiple select box values using jQuery?

jQuery .val()

  var foo = $('#multiple').val(); 

How to get multiple selected values of select box in php?

If you want PHP to treat $_GET['select2'] as an array of options just add square brackets to the name of the select element like this: <select name="select2[]" multiple …

Then you can acces the array in your PHP script

<?php
header("Content-Type: text/plain");

foreach ($_GET['select2'] as $selectedOption)
echo $selectedOption."\n";

$_GET may be substituted by $_POST depending on the <form method="…" value.

I can't get multiple selected values of select box in php

the code work just right for me:

/home/vagrant/foo/index.php:3:
array (size=2)
'classe' =>
array (size=2)
0 => string '| adjective |' (length=13)
1 => string '| adverb |' (length=10)
'submitSave' => string 'Save' (length=4)

have some special config in PHP?

my test:

<?php

var_dump($_POST);

?>
<form method="POST">
<div class="col-75">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.css" rel="stylesheet"/>
<select id="classe" name="classe[]" multiple name="event_type[]" class="form-control" required>
<option value="| adjective |">adjective</option>
<option value="| adverb |">adverb</option>
<option value="| noun |">noun</option>
<option value="| verb |">verb</option>
</select>
<script type="text/javascript">
var s2 = $("#classe").select2({
placeholder: "Select",
tags: true
});

</script>
</div>
<div class="row">

<td><input type="submit" value="Save" name="submitSave"></td>
</div>
</form>

edit:

when yo receive array data in PHP, in your case:

<select name="classes[]" >

the PHP var is $_POST['classes'] not $_POST['classes[]'] and it is an array, if you want to use it as an string you have to use implode



Related Topics



Leave a reply



Submit