我试图制作一个简单的联系表单, 我有两个文件,contact.php和index.php
我希望我的index.php文件中的"查询类型"我将这些选项放在contact.php文件中的数组中,如下所示:
<?php
class Contact{
public static $types = array(
1 => 'Product enquiry',
2 => 'Billing enquiry',
3 => 'Support enquiry'
);
}
&#13;
我还在index.php文件中包含了contact.php:
<?php require_once('file:///D:/Simple%20Contact%20Form/Liberay/Contact.php'); ?>
&#13;
但经过多次尝试后,我无法在下拉字段中看到任何选项,所以可能它的连接可能是什么?当我尝试使用php代码时,我是否必须将它放在像Xampp这样的本地服务器上?
这是index.php的完整代码:
<?php require_once('file:///D:/Simple%20Contact%20Form/Liberay/Contact.php'); ?>
<!DOCOTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Simple contact form with PHP</title>
<link rel="stylesheet" type="text/css" href="file:///D:/Simple%20Contact%20Form/CSS/core.css"/>
</head>
<body>
<form method="post" id="formContact" class="large-8 large-centered columns custom">
<fieldset>
<legend>Simple Contact Form with PHP</legend>
<div class="large-6 columns">
<label for="first_name">First name: *</label>
<input
type="text"
name="first_name"
id="first_name"
placeholder="Your first name"/>
</div>
<div class="large-6 columns">
<label for="last_name">Last name: *</label>
<input type="text"
name="last_name"
id="last_name"
placeholder="Your last name"/>
</div>
<div class="large-6 columns">
<label for="first_name">Email address: *</label>
<input type="email"
name="email"
id="email"
placeholder="Your Email address"/>
</div>
<div class="large-6 columns">
<label for="type">Enquiry type: *</label>
<select
name="type"
id="type">
<option value="">Select one</option>
<?php if (!empty(Contact::$types)) { ?>
<?php foreach(Contact::$types as $id => $type) { ?>
<option value="<?php echo $id; ?>"><?php echo $type; ?></option>
<?php } ?>
</select>
</div>
<div class="large-12 columns">
<label for="enquiry">Enquiry: *</label>
<textarea name="enquiry" id="enquiry" placeholder=" Your message"></textarea>
</div>
<div class="large-12 columns">
<button class="button small">Send message</button>
</div>
</fieldset>
</form>
<script src="file:///D:/Simple%20Contact%20Form/jquery.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="file:///D:/Simple Contact Form/js/core.js"></script>
</body>
</html>
&#13;
*对不起,如果有一点点混乱,但我尽我所能( - :
答案 0 :(得分:2)
如果您正在使用XAMPP,请将所有文件放在 htdocs 文件夹下。你提到了
<?php require_once('file:///D:/Simple%20Contact%20Form/Liberay/Contact.php'); ?>
- 指的是本地文件路径。