简体   繁体   English

PHP 表单多个输入

[英]PHP Form Multiple Inputs

I am having issues with php and form handling.我在处理 php 和表单时遇到问题。 I want to be able to click a dropdown box(like you can do with a form in html, with the different options tags) in php, and allow the selection to take the designated value.我希望能够在 php 中单击一个下拉框(就像您可以使用 html 中的表单,使用不同的选项标签一样),并允许选择采用指定的值。

Here is what I have :这是我所拥有的:

<input value="<?php echo isset($results['example']) ? $results['example']: ''; ?>" class="form-control" name="data[example]" placeholder="Example">

That populates with a place you can type in input text, which is accepted perfectly in post, but I do not want the user typing in data, only selecting from options, such as this html form does :这填充了一个你可以输入输入文本的地方,这在帖子中被完美接受,但我不希望用户输入数据,只从选项中选择,比如这个 html 表单:

<form action="example.php">
<option value="11">apples</option>
<option value="12">bananas</option>
<option value="13">oranges</option>
</form>

Here is an edit using the data given :这是使用给定数据的编辑:

<form>
                            <select name="example">
                                <option value="<?php echo isset($results['example']) ? $results['example']: ''; ?>">apples</option>
                                <option value="<?php echo isset($results['example']) ? $results['example']: ''; ?>">oranges</option>
                                <option value="<?php echo isset($results['example']) ? $results['example']: ''; ?>">bananas</option>
                            </select>
                        </form>

I did not add the action because it will be posted with other data, but did try both ways(with and without action="post.php") and it does not work...我没有添加动作,因为它会与其他数据一起发布,但确实尝试了两种方式(有和没有动作 =“post.php”),但它不起作用......

Defining your options inside a select tag在 select 标签中定义您的选项

<select>
<option value="11">apples</option>
<option value="12">bananas</option>
<option value="13">oranges</option>
</select>

Should give you in your post the position (value) of the selected item.应该在您的帖子中为您提供所选项目的位置(值)。 Then in your php pass value to the selected items *11,12,13 = apples,bananas,oranges**然后在您的 php 中将值传递给所选项目 *11,12,13 = apples,bananas,oranges**

Hope it help希望有帮助

你需要一个<select name="name"> </select>围绕你的选项

So you are looking for a dropdown I guess:所以你正在寻找一个下拉菜单,我猜:

<form action="example.php">
    <select name="fruit">
        <option value="1">Apple</option>
        <option value="2">Banana</option>
        <option value="3">Orange</option>
    </select>
</form>

On submiting the form you can get the value like: $_POST['fruit'] (in this case).在提交表单时,您可以获得如下值: $_POST['fruit'] _ $_POST['fruit'] (在本例中)。

I think you need something like that我想你需要这样的东西

<form action="example.php">
    <select name="fruit">
        <option value="<?php echo isset($results['example']) ? $results['example']: ''; ?>">apples</option>
    </select>
</form>

I'd say the issue is not PHP, I think you just need to use the SELECT and OPTION form tags:我想说问题不是 PHP,我认为你只需要使用SELECTOPTION表单标签:

You are specifying an INPUT tag, which by definition allows the user to input data.您正在指定一个INPUT标签,根据定义,它允许用户输入数据。

<form action="example.php">
 <select class="form-control" name="data[example]">
    <option value="<?php echo isset($results['example']) ? $results['example']: ''; ?>"">
</select>
</form>

use type="checkbox", so you can select one more使用 type="checkbox",这样你就可以多选一个

 <input type="checkbox" name="vehicle[]" value="Bike"> I have a bike<br> <input type="checkbox" name="vehicle[]" value="Car"> I have a car<br> <input type="checkbox" name="vehicle[]" value="Boat" checked> I have a boat<br>

in php在 php 中

 <?php $vehicleArray=''; foreach($_POST['vehicle'] as $value) { $vehicleArray.=$value.','; } //output 'Bike,Car,Boat' ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM