Javascript 如何使用onclick函数验证CSV文件格式?
如何验证我的CSV格式,我在html表单中使用“必需”来验证空值。我尝试使用onclick函数来使用alert box进行验证,但在javascript中添加php代码后,alert box不起作用。下面是我的代码。有人能给我建议一个解决办法吗Javascript 如何使用onclick函数验证CSV文件格式?,javascript,php,html,validation,csv,Javascript,Php,Html,Validation,Csv,如何验证我的CSV格式,我在html表单中使用“必需”来验证空值。我尝试使用onclick函数来使用alert box进行验证,但在javascript中添加php代码后,alert box不起作用。下面是我的代码。有人能给我建议一个解决办法吗 <?php require_once "lib/base.inc.php"; ?> <script> function storeQueEmail(){ <?php $file = $_FILES[c
<?php
require_once "lib/base.inc.php";
?>
<script>
function storeQueEmail(){
<?php
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
$record['contact_first'] = $data[0];
$record['contact_last'] = $data[1];
$record['contact_email'] = $data[2];
$record['subject'] = $_REQUEST['subject'];
$record['message'] = $_REQUEST['message'];
$record['status'] = 0;
$oAdminEmail->insertQueEmail($record);
}
} while ($data = fgetcsv($handle,1000,",","'"));
?>;
alert('jyfkyugu');
window.location.href="cronjob_sendemail.php";
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" >
Subject : <br/>
<input type="text" name="subject" id="subject" required/> <br/>
Choose your file: <br />
<input name="csv" type="file"id="csv" required/> <br/>
Content : <br/>
<textarea name="message" cols="50" rows="10" required></textarea><br/>
<input type="submit" name="submit" value="Submit" onclick="storeQueEmail()"/>
</form>
</body>
</html>
函数storeQueEmail(){
使用PHP和MySQL导入CSV文件
主题:
选择您的文件:
内容:
。我无法理解这个过程告诉我什么。我只是一个新程序员。你能给我一个示例代码来工作吗?我找到了另一种方法,在输入字段中添加“accept=“.csv”。它只帮助我过滤csv文件。因此我不需要对上载字段进行额外的验证。