如何从一个变量中的多个表单搜索字段中捕获数据

I have an html search form with multiple fields like select, textarea and text inputs. I need the values from all the fields to be stored into $input in the php search form but I'm not sure how to store them into one variable called $input on the php page.

<form name="search" method="post" action="http://example.com/search/">
Seach for: <input type="text" name="find" /> <input type="submit"  
name="search" value="Search" />
Search for movies by Type
<select name="find">
<option value="Sci-Fi" selected>Sci-Fi</option>
<option value="Comedy">Comedy</option>
<option value="Drama">Drama</option>
</select>
</form>

//on search.php need to 'find' to be data from several form inputs
$input = $_POST['find'];

If you give multiple inputs the same name, $_POST['find'] will just contain the input from one of them (the last one, I think). You need to either give them different names, or you can end the name with []. When you do the latter, PHP will put all the inputs into an array.

<form name="search" method="post" action="http://example.com/search/">
Seach for: <input type="text" name="find[]" /> <input type="submit" name="search" value="Search" />
Search for movies by Type
<select name="find[]">
    <option value="Sci-Fi" selected>Sci-Fi</option>
    <option value="Comedy">Comedy</option>
    <option value="Drama">Drama</option>
</select>
</form>

With this, you can do:

$input = implode(' ', array_filter($_POST['find']));

array_filter will remove any empty values, then the rest will be concatenated together with space between them.

Make your $input an array. For example:

$input = array(
    "user" => $_POST['username'],
    "find" => $_POST['find'],
);

Or simply add everything to $input by doing:

$input .= $_POST['username'];
$input .= $_POST['find'];
<?php
array_pop($_POST); // To delete Submit button from $_POST
foreach(array_filter($_POST) as $key=> $val)
{
    $input .= "$val";
}
?>