在PHP $ form内添加选项下拉菜单

时间:2019-07-25 08:23:14

标签: php html forms

我已经在php中创建了一个表单,在该表单中我设法使文本字段正常工作。但是,我希望对某些选项(例如下面的选项)提供一个选择下拉选项。

1

这是我表格的当前情况。

2

这是PHP代码。

<?php
  $form = [
      0 => [
          'label'       => 'Property Name',
          'type'        => 'text',
          'name'        => 'lease_name',
          'placeholder' => 'Name',
          'value'       => (isset($_POST['lease_name'])) ? $_POST['lease_name'] : $rowProperty['lease_name'],
      ],
      1 => [
          'label'       => 'Property Type',
          'type'        => 'text',
          'name'        => 'lease_type',
          'placeholder' => 'Type',
          'value'       => (isset($_POST['lease_type'])) ? $_POST['lease_type'] : $rowProperty['lease_type'],
      ],
      2 => [
          'label'       => 'Property Address',
          'type'        => 'text',
          'name'        => 'lease_address',
          'placeholder' => 'Address',
          'value'       => (isset($_POST['lease_address'])) ? $_POST['lease_address'] : $rowProperty['lease_address'],
      ],
      3 => [
          'label'       => '# of Bedrooms',
          'type'        => 'text',
          'name'        => 'lease_bedroom',
          'placeholder' => '# of Bedrooms',
          'value'       => (isset($_POST['lease_bedroom'])) ? $_POST['lease_bedroom'] : $rowProperty['lease_bedroom'],
      ],
      4 => [
          'label'       => '# of Bathrooms',
                            'type'        => 'text',
          'name'        => 'lease_bathroom',
          'placeholder' => '# of Bathrooms',
          'value'       => (isset($_POST['lease_bathroom'])) ? $_POST['lease_bathroom'] : $rowProperty['lease_bathroom'],
      ],
      5 => [
          'label'       => 'Floor Area',
          'type'        => 'text',
          'name'        => 'lease_floor_area',
          'placeholder' => 'Floor Area',
          'value'       => (isset($_POST['lease_floor_area'])) ? $_POST['lease_floor_area'] : $rowProperty['lease_floor_area'],
      ],
      6 => [
          'label'       => 'Lot Area',
          'type'        => 'text',
          'name'        => 'lease_lot_area',
          'placeholder' => 'Lot Area',
          'value'       => (isset($_POST['lease_lot_area'])) ? $_POST['lease_lot_area'] : $rowProperty['lease_lot_area'],
      ],
      7 => [
          'label'       => 'Furnishing',
          'type'        => 'text',
          'name'        => 'lease_furnishing',
          'placeholder' => 'Furnishing',
          'value'       => (isset($_POST['lease_furnishing'])) ? $_POST['lease_furnishing'] : $rowProperty['lease_furnishing'],
      ],
      8 => [
          'label'       => 'Term (# of Years)',
          'type'        => 'text',
          'name'        => 'lease_term',
          'placeholder' => 'Terms',
          'value'       => (isset($_POST['lease_term'])) ? $_POST['lease_term'] : $rowProperty['lease_term'],
      ],
      9 => [
          'label'       => 'Parking Spaces',
          'type'        => 'text',
          'name'        => 'lease_parking_space',
          'placeholder' => 'Parking Space',
          'value'       => (isset($_POST['lease_parking_space'])) ? $_POST['lease_parking_space'] : $rowProperty['lease_parking_space'],
      ],
      10 => [
          'label'       => 'Property Price',
          'type'        => 'text',
          'name'        => 'lease_price',
          'placeholder' => 'Price',
          'value'       => (isset($_POST['lease_price'])) ? $_POST['lease_price'] : $rowProperty['lease_price'],
      ],
      11 => [
          'label'       => 'Property Condition',
          'type'        => 'text',
          'name'        => 'lease_condition',
          'placeholder' => 'Condition',
          'value'       => (isset($_POST['lease_condition'])) ? $_POST['lease_condition'] : $rowProperty['lease_condition'],
      ],
      12 => [
          'label'       => 'Description',
          'type'        => 'textarea',
          'name'        => 'lease_description',
          'placeholder' => 'Description',
          'value'       => (isset($_POST['lease_description'])) ? $_POST['lease_description'] : $rowProperty['lease_description'],
      ],
  ];
?>

我希望卧室,浴室,家具,家具和停车位采用下拉选项格式。我不太确定如何在<?php $form =[] ?>中实现它,或如何修改'type' => 'text'(文本字段)以将其更改为我想要的样子。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

根据您的PHP结构,您必须向数组添加一个新的表单项。此新项目应为eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wYW5pZXMiOlt7IklkIjoxLCJDb2RlIjoiQzAxIiwiTmFtZSI6IkNvbXBhbnkgSSIsIkJyYW5jaGVzIjpudWxsLCJVc2VycyI6W3siSWQiOjEsIk5hbWUiOiJVc2VyIE9uZSJ9LHsiSWQiOjIsIk5hbWUiOiJVc2VyIFR3byJ9LHsiSWQiOjMsIk5hbWUiOiJVc2VyIFRocmVlIn1dfSx7IklkIjoyLCJDb2RlIjoiQzAzIiwiTmFtZSI6IkNvbXBhbnkgSUkiLCJCcmFuY2hlcyI6bnVsbCwiVXNlcnMiOm51bGx9LHsiSWQiOjMsIkNvZGUiOiJDMDMiLCJOYW1lIjoiQ29tcGFueSBJSUkiLCJCcmFuY2hlcyI6bnVsbCwiVXNlcnMiOlt7IklkIjoxLCJOYW1lIjoiVXNlciBPbmUifSx7IklkIjoyLCJOYW1lIjoiVXNlciBUd28ifSx7IklkIjozLCJOYW1lIjoiVXNlciBUaHJlZSJ9XX1dLCJicmFuY2hlcyI6W3siSWQiOjEsIkNvbXBhbnlJZCI6MSwiQ29kZSI6IkIwMSIsIk5hbWUiOiJCcmFuY2ggMS4xIn0seyJJZCI6MiwiQ29tcGFueUlkIjoxLCJDb2RlIjoiQjAyIiwiTmFtZSI6IkJyYW5jaCAxLjIifSx7IklkIjozLCJDb21wYW55SWQiOjEsIkNvZGUiOiJCMDMiLCJOYW1lIjoiQnJhbmNoIDEuMyJ9LHsiSWQiOjQsIkNvbXBhbnlJZCI6MiwiQ29kZSI6IkIwNCIsIk5hbWUiOiJCcmFuY2ggMi4xIn0seyJJZCI6NSwiQ29tcGFueUlkIjoyLCJDb2RlIjoiQjA1IiwiTmFtZSI6IkJyYW5jaCAyLjIifV19.ysjwBa3YeYNmVB0fVEh95wL0zt8Krb-T4VRpWKWIfbU 类型。

例如:

select

注意:当您将数组作为代码编写时,如果键从0到N,则可以忽略键。

您用于显示选择内容的HTML / PHP代码应为:

13 => [
    'label'      => 'Your select label',
    'type'       => 'select',
    'name'       => 'your_select_name',
    'placeholder'=> null, // There is not placeholder in select field
    'value'      => ['Bedrooms', 'Bathrooms', 'Furnishing', 'Terms', 'Parking Space'], // Your select options, the key should be 'values' but in this way it is like the others 
]