如何使用onclick功能验证CSV文件格式?

时间:2014-03-25 02:22:34

标签: javascript php html validation csv

如何验证我的CSV格式,我在html表单中使用“required”来验证null值。我尝试使用onclick函数来验证使用警告框但在我在javascript中添加php代码后警报框不起作用。以下是我的代码。有人可以向我建议解决方案吗?

<?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> 

0 个答案:

没有答案