【发布时间】:2019-01-09 09:15:44
【问题描述】:
我有以下问题.. 我必须确保最初在下表中输入数据,然后在按下“提交”按钮后运行脚本 createDirectory () 并重定向到包含在头功能。除了被重定向之外,您还必须在页面链接中输入“idCantire”字段 .. 根据我刚刚所做的尝试,一旦我按下按钮,它会将我重定向到同一页面,但都是白色的。
您有什么解决方案可以提供给我吗? 我认为用一个简单的标题我可以做重定向......
<!doctype html>
<?php
$idCantiere = $_GET["idCantiere"];
session_start();
if(!isset($_SESSION["username"])){
header('location: ../../../index.php');
}
else
{
?>
<html>
<?php
?>
<head>
<style>
#senzaBordi{border-style: none;}
.bordi{
border-width: 5px;
border-style: solid;
}
</style>
<link href="../bootstrap/bootstrap.css" rel="stylesheet" id="bootstrap-css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Affidataria / Soci ATI</title>
</head>
<script>
function color(el){
if(el.value=="OK"){
el.parentNode.parentNode.style.backgroundColor="#00ff00";
}
else{
el.parentNode.parentNode.style.backgroundColor="#B35556";
}
}
</script>
<body>
<?php
function createDirectory()
{
$nomeCantiere = $_POST["nomeCantiere"];
date_default_timezone_set('Europe/Rome');
$date = date('Y-m-d');
chdir("../../../../Archivio/Cantieri");
mkdir($date."_".$nomeCantiere);
echo "<script type='text/javascript'>alert('Done!');</script>";
header('location:affidatario2.php?idCantiere=<?php echo $idCantiere?>');
}
?>
<form method="POST" action="">
<?php
$idAffidataria = rand();
?>
<table cellspacing="0" cellpadding="0" border="3px" id="myTable" class="table table-bordered" id="tab1" name="tab1" >
<?php
if (!isset($_POST['submit'])) {
?>
<tr>
<td style=" border-style: none;" width="64"></td>
<td width="1479" colspan="8" align="center" bgcolor="#a5dfff" style="border: 2px solid black;"><strong>AFFIDATARIA</strong></td>
<td style=" border-style: none;" width="64"></td>
<td width="1088" colspan="8" align="center" bgcolor="#B35556"><strong>R.I. / C.S.E.</strong></td>
</tr>
<tr>
<td style=" border-style: none;"></td>
<td bgcolor="#CDECFD"><strong>I.D.</strong></td>
<td colspan="4" bgcolor="#CDECFD"><strong>Documento</strong></td>
<td colspan="2" bgcolor="#CDECFD"><strong>Note</strong></td>
<td bgcolor="#CDECFD" ></td>
<td style=" border-style: none;"></td>
<td bgcolor="#B35556">Verifica</td>
<td bgcolor="#B35556">Note sul doc</td>
</tr>
<tr>
<td style=" border-style: none;"></td>
<td bgcolor="#CDECFD" style="font-weight: bold">1</td>
<td colspan="2" bgcolor="#CDECFD" style="font-weight: bold">Cantiere</td>
<td colspan="4" bgcolor="#CDECFD"><input type="text" class="form-control" style="width: 100%;" name="nomeCantiere" id="nomeCantiere" /> </td>
<td bgcolor="#CDECFD" ></td>
</tr>
<tr>
<td style=" border-style: none;"></td>
<td bgcolor="#CDECFD" style="font-weight: bold">1.1</td>
<td colspan="2" bgcolor="#CDECFD" style="font-weight: bold">Ragione Sociale</td>
<td colspan="4" bgcolor="#CDECFD"><input type="text" class="form-control" style="width: 100%;" name="ragioneSociale" id="ragioneSociale"/> </td>
<td bgcolor="#CDECFD" ></td>
</tr>
<tr>
<td style=" border-style: none;"></td>
<td bgcolor="#CDECFD" style="font-weight: bold">1.2</td>
<td colspan="2" bgcolor="#CDECFD" style="font-weight: bold">Tipologia Affidataria</td>
<td colspan="2" bgcolor="#CDECFD" style="font-weight: bold">
<select name="tipologiaAffidataria" class="form-control chkEdit" enable>
<option value="Affidataria" selected="selected">Affidataria</option>
<option value="Mandataria">Mandataria</option>
<option value="Mandante">Mandante</option>
<option value="Esecutrice">Esecutrice</option>
</select>
</td>
<td bgcolor="#CDECFD"style=" border-style: none;" ></td>
<td bgcolor="#CDECFD"style=" border-style: none;" ></td>
<td bgcolor="#CDECFD"style=" border-style: none;" ></td>
</tr>
<tr>
<td style=" border-style: none;"></td>
<td bgcolor="#CDECFD" style="font-weight: bold">2</td>
<td bgcolor="#CDECFD" style="font-weight: bold">Addetto sicurezza</td>
<td bgcolor="#CDECFD"><input type="text" style="width: 220px;" class="form-control" name="addettoSicurezza" id="addettoSicurezza" value="<?php echo $savedAddettoSicurezza; ?>"/></td>
<td colspan="2" bgcolor="#CDECFD">Mail</td>
<td bgcolor="#CDECFD"><input type="text" style="align:center;" class="form-control" style="width: 100%;" name="mailAffidataria" id="mailAffidataria" value="<?php echo $savedMailAffidataria; ?>"/></td>
<td bgcolor="#CDECFD"colspan="2"><input type="submit" name="submit" value="Crea Directory Affidataria" href="affidatario2.php?idCantiere=<?php echo $idCantiere?>" class="btn btn-warning"></td>
</form>
</tr>
<?php
}
else{
createDirectory();
}
?>
</table>
<script>
function openPage(pageName,elmnt,color) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.backgroundColor = "";
}
document.getElementById(pageName).style.display = "block";
elmnt.style.backgroundColor = color;
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
<script language="javascript">
function controlla(){
x=document.prova;
if (x.scelta.value=="si"){
window.location.href = 'subAffidatario.php'
return false;
}
if (x.scelta.value=="no"){
alert("Hai risposto no");
window.location.href = 'affidatario.php'
return false;
}
}
</script>
<style>
#drop_file_zone {
background-color: #37bf00;
border: #999 5px ;
width: 150px;
height: 150px;
padding: 8px;
font-size: 13px;
}
#drag_upload_file {
width:50%;
margin:0 auto;
}
#drag_upload_file p {
text-align: center;
}
#drag_upload_file #selectfile {
display: none;
}
.coloreTdDrop{
background-color: #37bf00;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
var fileobj;
function upload_file(e) {
e.preventDefault();
fileobj = e.dataTransfer.files[0];
ajax_file_upload(fileobj);
}
function file_explorer() {
document.getElementById('selectfile').click();
document.getElementById('selectfile').onchange = function() {
fileobj = document.getElementById('selectfile').files[0];
ajax_file_upload(fileobj);
};
}
function ajax_file_upload(file_obj) {
if(file_obj != undefined) {
var form_data = new FormData();
form_data.append('file', file_obj);
$.ajax({
type: 'POST',
url: 'ajax.php',
contentType: false,
processData: false,
data: form_data,
success:function(response) {
alert(response);
$('#selectfile').val('');
}
});
}
}
</script>
<script language="JavaScript" type="text/javascript">
<!--
function protect(anObject, protection)
{
if (anObject == null) {
return true;
} // if (anObject == null)
var members = anObject.children.length;
var i = 0;
for (i=0;i<members;i++)
{
var curObject = anObject.children.item(i);
if (curObject != null)
{
protect(curObject,protection);
} // if (curObject != null)
} // for (i=0;i<=members;i++)
anObject.disabled = protection;
return true;
} // function protect(anObject, protection)
//-->
</script>
</body>
</html>
<?php } ?>
【问题讨论】:
-
脚本和 HTML 输出都非常需要整理出来……尝试遵循IPO-Model。并修复您的 HTML - 例如,您先打开
form,然后打开table,然后按/form、/tr、/table的顺序关闭这些元素。 -
然后你打开你的表单,然后你有一个
if (!isset($_POST['submit']))- 然后你只关闭该分支内的表单,但不是在其他情况下。再次:可怕的混乱,恕我直言,应该从头开始重写。
标签: javascript php html header mkdir