[RISOLTO] [JS e PHP] Problemi codici onload (Body)
-
- Entusiasta Emergente
- Messaggi: 1331
- Iscrizione: lunedì 26 aprile 2010, 17:36
- Desktop: gnome
- Distribuzione: ubuntu 23.04/22.04
- Sesso: Maschile
- Località: Massa(MS)
[RISOLTO] [JS e PHP] Problemi codici onload (Body)
Salve come faccio ad includere questo codice nella pagina che ha già un body iniziale?
<body onLoad="collapsePages()">
questo è il mio codice ancora di prova.. poi lo sistemo:
[code2=php]<?php
session_start();
include("inc.php");
include("admin.php");
ini_set("upload_max_filesize","300M");
include("layout/template.php");
layout_header();
?>
<script type=text/javascript>
function collapseElement(obj)
{
var el = document.getElementById(obj);
el.style.display = 'none';
}
function expandElement(obj)
{
var el = document.getElementById(obj);
el.style.display = '';
}
function collapsePages()
{
var numFormPages = 3;
for(i=2; i <= numFormPages; i++)
{
currPageId = ('page_' + i);
collapseElement(currPageId);
}
}
</script>
<?php
if(empty($_GET["dir"]))
{
echo '<h2>403</h2>';
}else
{
?>
<?php
try {
$query = "select * from photo_categories where dir = :dir";
$stmt = $db->prepare( $query );
$stmt->bindParam(':dir', $_GET['dir'], PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row > 0)
{
$id_categories = $row["id"];
$dir_ = $row["dir"];
}else
{
$msg = "404";
}
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
?>
<?php
$id_users = $_SESSION["id_users"];
$active = isset($_POST['active']) ? $_POST['active'] : "";
$fine = false;
if( isset($_POST['submit']) )
{
if (empty($_POST["active"]))
{
$error = "empty active";
}else if(empty($_POST["data_reg"]))
{
$error = 'empty data_reg';
}elseif(!isData($_POST["data_reg"]))
{
$error = "La data deve avere il formato come segue : ".date("Y-m-d H:i:s")."";
}
else
{
$file = explode('.',$_FILES['upload_file']['name']);
$file_name = sha1($_FILES['upload_file']['name']).'.'.$file[count($file)-1];
move_uploaded_file($_FILES['upload_file']['tmp_name'], "../public/photo/".$dir_."/tmp/".$file_name."");
$resizer = new ImageResizer("../public/photo/".$dir_."/tmp/".$file_name,"../public/photo/".$dir_."/big/".$file_name."");
$resizer->resizeImage(800,600);
$resizer = new ImageResizer("../public/photo/".$dir_."/tmp/".$file_name,"../public/photo/".$dir_."/thumb/".$file_name."");
$resizer->resizeImage(300,250);
$id_categories = $row["id"];
$query = "INSERT INTO photo (id_users,id_categories,title,url,content,active,data_reg)VALUES(:id_users,:id_categories,:title,:url,:content,:active,:data_reg)";
$stmt = $db->prepare($query);
$stmt->bindParam(':id_users', $id_users, PDO::PARAM_INT);
$stmt->bindParam(':id_categories',$id_categories, PDO::PARAM_INT);
$stmt->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
$stmt->bindParam(':url',$file_name, PDO::PARAM_STR);
$stmt->bindParam(':content', $_POST["content"], PDO::PARAM_STR);
$stmt->bindParam(':active', $_POST["active"], PDO::PARAM_INT);
$stmt->bindParam(':data_reg', $_POST['data_reg'], PDO::PARAM_STR);
unlink("../public/photo/".$dir_."/tmp/".$file_name."");
if($stmt->execute())
{
header("location: photo_album.php?id=".$id_categories."");
}else
{
$error = 'Errore.';
}
}
}
if(!$fine)
{
if(isset($error)){ echo '<p class="info_error">'.$error.'</p>';}
?>
<?php
?>
<body onLoad="collapsePages()">
<div id="mainForm">
<form action="?dir=<?php echo $row["dir"]; ?>" method="post" enctype="multipart/form-data" onSubmit="return">
<!--Page 1-->
<ul id="page_1">
<li>
<h2>Immagine : </h2>
<input type="file" name="upload_file"/>
</li>
<li>
<input type="button" onClick="collapseElement('page_1'); expandElement('page_2');" value="Continue"/>
</li>
<div class="meter"><span style="width: 50%"></span></div>
</ul>
<!--Page 2-->
<ul id="page_2">
<li>
<li>
<table>
<tr>
<td>Titolo</td>
<td><input type="text" name="title" value="<?php if(isset($_POST['title'])){echo htmlspecialchars($_POST['title']);}?>"></td>
</tr>
<tr>
<td>Content</td>
<td><textarea name="content" cols="100" rows="30"><?php if(isset($_POST['content'])){echo $_POST['content'];}?></textarea></td>
</tr>
<tr>
<td>Stato</td>
<td>Pubblico<input type="radio" name="active" value="1" <?php if($active=='1') echo 'checked="checked"'?>/>
Nascosto<input type="radio" name="active" value="2" <?php if($active=='2') echo 'checked="checked"'?>/>
</td>
<tr>
<td>Data</td>
<td><input type="text" name="data_reg" value="<?php if(isset($_POST['data_reg'])){echo htmlspecialchars($_POST['data_reg']);}else { echo date("Y-m-d H:i:s"); }?>"></td>
</tr>
</tr>
<td>
<input type='hidden' name='action' value='upload' />
</td>
</tr>
</table>
<li>
<input type="submit" value="Submit" name="submit">
<input type="button" onClick="collapseElement('page_2'); expandElement('page_1');" value="Back"/>
</li>
<div class="meter"><span style="width: 100%"></span></div>
</ul>
</form>
<?php
}
}
?>
<?php
layout_footer();
?>[/code2]
e questo è il file template.php:
[code2=php]<?php function layout_header() { ?>
<!DOCTYPE html>
<head>
<title>Amministratore</title>
<meta charset="utf-8">
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/main.css" rel="stylesheet" type="text/css">
</head>
<div id="header"><h1>Amministratore</h1></div>
<div id="navigation">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="post.php">News</a></li>
<li><a href="pages.php">Pagine</a></li>
<li><a href="photo.php">Foto</a></li>
<li><a href="sistema.php">Sistema</a></li>
<li><a href="users.php">Utenti</a></li>
<li><a href="../logout.php">Esci</a></li>
<li><a href="../index.php">Torna al sito</a></li>
</ul>
</div>
<div id='main'>
<div id='content'>
<?php } ?>
<?php function layout_footer() { ?>
</div>
</div>
<div id='footer' align="center">
© <?php echo date("Y"); ?>
</div>
</body>
</html>
<?php } ?>[/code2]
c'è un sistema più comodo ?
ho devo fare una funzione che mi caricasse gli script js , quando li voglio io?
grazie mille e buona serata a domani pomeriggio.
<body onLoad="collapsePages()">
questo è il mio codice ancora di prova.. poi lo sistemo:
[code2=php]<?php
session_start();
include("inc.php");
include("admin.php");
ini_set("upload_max_filesize","300M");
include("layout/template.php");
layout_header();
?>
<script type=text/javascript>
function collapseElement(obj)
{
var el = document.getElementById(obj);
el.style.display = 'none';
}
function expandElement(obj)
{
var el = document.getElementById(obj);
el.style.display = '';
}
function collapsePages()
{
var numFormPages = 3;
for(i=2; i <= numFormPages; i++)
{
currPageId = ('page_' + i);
collapseElement(currPageId);
}
}
</script>
<?php
if(empty($_GET["dir"]))
{
echo '<h2>403</h2>';
}else
{
?>
<?php
try {
$query = "select * from photo_categories where dir = :dir";
$stmt = $db->prepare( $query );
$stmt->bindParam(':dir', $_GET['dir'], PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row > 0)
{
$id_categories = $row["id"];
$dir_ = $row["dir"];
}else
{
$msg = "404";
}
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
?>
<?php
$id_users = $_SESSION["id_users"];
$active = isset($_POST['active']) ? $_POST['active'] : "";
$fine = false;
if( isset($_POST['submit']) )
{
if (empty($_POST["active"]))
{
$error = "empty active";
}else if(empty($_POST["data_reg"]))
{
$error = 'empty data_reg';
}elseif(!isData($_POST["data_reg"]))
{
$error = "La data deve avere il formato come segue : ".date("Y-m-d H:i:s")."";
}
else
{
$file = explode('.',$_FILES['upload_file']['name']);
$file_name = sha1($_FILES['upload_file']['name']).'.'.$file[count($file)-1];
move_uploaded_file($_FILES['upload_file']['tmp_name'], "../public/photo/".$dir_."/tmp/".$file_name."");
$resizer = new ImageResizer("../public/photo/".$dir_."/tmp/".$file_name,"../public/photo/".$dir_."/big/".$file_name."");
$resizer->resizeImage(800,600);
$resizer = new ImageResizer("../public/photo/".$dir_."/tmp/".$file_name,"../public/photo/".$dir_."/thumb/".$file_name."");
$resizer->resizeImage(300,250);
$id_categories = $row["id"];
$query = "INSERT INTO photo (id_users,id_categories,title,url,content,active,data_reg)VALUES(:id_users,:id_categories,:title,:url,:content,:active,:data_reg)";
$stmt = $db->prepare($query);
$stmt->bindParam(':id_users', $id_users, PDO::PARAM_INT);
$stmt->bindParam(':id_categories',$id_categories, PDO::PARAM_INT);
$stmt->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
$stmt->bindParam(':url',$file_name, PDO::PARAM_STR);
$stmt->bindParam(':content', $_POST["content"], PDO::PARAM_STR);
$stmt->bindParam(':active', $_POST["active"], PDO::PARAM_INT);
$stmt->bindParam(':data_reg', $_POST['data_reg'], PDO::PARAM_STR);
unlink("../public/photo/".$dir_."/tmp/".$file_name."");
if($stmt->execute())
{
header("location: photo_album.php?id=".$id_categories."");
}else
{
$error = 'Errore.';
}
}
}
if(!$fine)
{
if(isset($error)){ echo '<p class="info_error">'.$error.'</p>';}
?>
<?php
?>
<body onLoad="collapsePages()">
<div id="mainForm">
<form action="?dir=<?php echo $row["dir"]; ?>" method="post" enctype="multipart/form-data" onSubmit="return">
<!--Page 1-->
<ul id="page_1">
<li>
<h2>Immagine : </h2>
<input type="file" name="upload_file"/>
</li>
<li>
<input type="button" onClick="collapseElement('page_1'); expandElement('page_2');" value="Continue"/>
</li>
<div class="meter"><span style="width: 50%"></span></div>
</ul>
<!--Page 2-->
<ul id="page_2">
<li>
<li>
<table>
<tr>
<td>Titolo</td>
<td><input type="text" name="title" value="<?php if(isset($_POST['title'])){echo htmlspecialchars($_POST['title']);}?>"></td>
</tr>
<tr>
<td>Content</td>
<td><textarea name="content" cols="100" rows="30"><?php if(isset($_POST['content'])){echo $_POST['content'];}?></textarea></td>
</tr>
<tr>
<td>Stato</td>
<td>Pubblico<input type="radio" name="active" value="1" <?php if($active=='1') echo 'checked="checked"'?>/>
Nascosto<input type="radio" name="active" value="2" <?php if($active=='2') echo 'checked="checked"'?>/>
</td>
<tr>
<td>Data</td>
<td><input type="text" name="data_reg" value="<?php if(isset($_POST['data_reg'])){echo htmlspecialchars($_POST['data_reg']);}else { echo date("Y-m-d H:i:s"); }?>"></td>
</tr>
</tr>
<td>
<input type='hidden' name='action' value='upload' />
</td>
</tr>
</table>
<li>
<input type="submit" value="Submit" name="submit">
<input type="button" onClick="collapseElement('page_2'); expandElement('page_1');" value="Back"/>
</li>
<div class="meter"><span style="width: 100%"></span></div>
</ul>
</form>
<?php
}
}
?>
<?php
layout_footer();
?>[/code2]
e questo è il file template.php:
[code2=php]<?php function layout_header() { ?>
<!DOCTYPE html>
<head>
<title>Amministratore</title>
<meta charset="utf-8">
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/main.css" rel="stylesheet" type="text/css">
</head>
<div id="header"><h1>Amministratore</h1></div>
<div id="navigation">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="post.php">News</a></li>
<li><a href="pages.php">Pagine</a></li>
<li><a href="photo.php">Foto</a></li>
<li><a href="sistema.php">Sistema</a></li>
<li><a href="users.php">Utenti</a></li>
<li><a href="../logout.php">Esci</a></li>
<li><a href="../index.php">Torna al sito</a></li>
</ul>
</div>
<div id='main'>
<div id='content'>
<?php } ?>
<?php function layout_footer() { ?>
</div>
</div>
<div id='footer' align="center">
© <?php echo date("Y"); ?>
</div>
</body>
</html>
<?php } ?>[/code2]
c'è un sistema più comodo ?
ho devo fare una funzione che mi caricasse gli script js , quando li voglio io?
grazie mille e buona serata a domani pomeriggio.
Ultima modifica di treled il domenica 1 marzo 2015, 10:37, modificato 1 volta in totale.
- SuperStep
- Entusiasta Emergente
- Messaggi: 2037
- Iscrizione: lunedì 19 dicembre 2011, 16:26
- Desktop: Unity
- Distribuzione: Ubuntu 16.04 LTS x86_64
- Sesso: Maschile
- Località: Somma Vesuviana (NA)
Re: [JS e PHP] Problemi codici onload (Body)
ci sono varie soluzioni in merito:
prima)
puoi chiamare l'esecuzione dello script a fondo pagina (quando tutti gli altri elementi si sono caricati
seconda)
puoi utilizzare la funzione che viene chiamata al load del body di default per inserire la tua funzione
terza)
puoi utilizzare addEventListener per aggiungere l'handler di funzione a quelli che verranno eseguiti durante la chiamata di un evento
prima)
puoi chiamare l'esecuzione dello script a fondo pagina (quando tutti gli altri elementi si sono caricati
Codice: Seleziona tutto
<html>
<head> ... </head>
<body>
...
</body>
<script>collapsePages();</script>
</html>
puoi utilizzare la funzione che viene chiamata al load del body di default per inserire la tua funzione
Codice: Seleziona tutto
<script>
document.body.onload=function(){collapsePages();};
</script>
puoi utilizzare addEventListener per aggiungere l'handler di funzione a quelli che verranno eseguiti durante la chiamata di un evento
Codice: Seleziona tutto
document.body.addEventListener("load", collapsePages, false);
ubuntu 16.04 LTS 64-bit - Memoria: 31,3 Gib - Processore: Intel Core i7-5960X CPU @ 3.00 GHz × 16 - Grafica: AMD Radeon HD 7800 Series - Disco: SSD 256 GB x 4 (RAID 01)
-
- Entusiasta Emergente
- Messaggi: 1331
- Iscrizione: lunedì 26 aprile 2010, 17:36
- Desktop: gnome
- Distribuzione: ubuntu 23.04/22.04
- Sesso: Maschile
- Località: Massa(MS)
Re: [JS e PHP] Problemi codici onload (Body)
invece se questo pezzo di codice .. qualcuno se me lo può convertire in jquery è più semplice.. perché la include nell'head <script></script>
[code2=javascript]<script type="text/javascript">
function collapseElement(obj)
{
var el = document.getElementById(obj);
el.style.display = 'none';
}
function expandElement(obj)
{
var el = document.getElementById(obj);
el.style.display = '';
}
function collapsePages()
{
var numFormPages = 3;
for(i=2; i <= numFormPages; i++)
{
currPageId = ('page_' + i);
collapseElement(currPageId);
}
}
</script>[/code2]
ora vedo i tuoi suggerimenti.
grazie mille.
[code2=javascript]<script type="text/javascript">
function collapseElement(obj)
{
var el = document.getElementById(obj);
el.style.display = 'none';
}
function expandElement(obj)
{
var el = document.getElementById(obj);
el.style.display = '';
}
function collapsePages()
{
var numFormPages = 3;
for(i=2; i <= numFormPages; i++)
{
currPageId = ('page_' + i);
collapseElement(currPageId);
}
}
</script>[/code2]
ora vedo i tuoi suggerimenti.
grazie mille.
- SuperStep
- Entusiasta Emergente
- Messaggi: 2037
- Iscrizione: lunedì 19 dicembre 2011, 16:26
- Desktop: Unity
- Distribuzione: Ubuntu 16.04 LTS x86_64
- Sesso: Maschile
- Località: Somma Vesuviana (NA)
Re: [JS e PHP] Problemi codici onload (Body)
apri un nuovo thread, non si possono inserire piu' argomenti nello stesso thread.
ubuntu 16.04 LTS 64-bit - Memoria: 31,3 Gib - Processore: Intel Core i7-5960X CPU @ 3.00 GHz × 16 - Grafica: AMD Radeon HD 7800 Series - Disco: SSD 256 GB x 4 (RAID 01)
- SuperStep
- Entusiasta Emergente
- Messaggi: 2037
- Iscrizione: lunedì 19 dicembre 2011, 16:26
- Desktop: Unity
- Distribuzione: Ubuntu 16.04 LTS x86_64
- Sesso: Maschile
- Località: Somma Vesuviana (NA)
Re: [JS e PHP] Problemi codici onload (Body)
se questo argomento e' risolto modifica il primo post anteponendo [RISOLTO] al titolo del post
ubuntu 16.04 LTS 64-bit - Memoria: 31,3 Gib - Processore: Intel Core i7-5960X CPU @ 3.00 GHz × 16 - Grafica: AMD Radeon HD 7800 Series - Disco: SSD 256 GB x 4 (RAID 01)
-
- Entusiasta Emergente
- Messaggi: 1331
- Iscrizione: lunedì 26 aprile 2010, 17:36
- Desktop: gnome
- Distribuzione: ubuntu 23.04/22.04
- Sesso: Maschile
- Località: Massa(MS)
Re: [JS e PHP] Problemi codici onload (Body)
no, non ho risolto con questo metodo.. ma ho cambiato metodo.. ho fatto delle popup etc..
grazie lo stesso.
grazie lo stesso.
Chi c’è in linea
Visualizzano questa sezione: 0 utenti iscritti e 9 ospiti