Wysyłanie formularza do określonego diva na stronie

0

witam mam taki problem mam formularz zrobiony i chcialbym zeby po kliknieciu wyslal on cala zawartosc do odpowiedniego diva

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('form').submit(function(e) {
        e.preventDefault();
        div = $(this).attr('action');
        desc = $('textarea[name="tresc"]').val();
desc = $('input[name="zrodlo"]').val();
		 desc = $('input[name="image"]').val();
		 desc = $('input[name="login"]').val();
		 desc = $('input[name="temat"]').val();
        $(div).html(desc)
    });
});
</script>


<div id="contener"></div>
<?php
echo'
<form action="temat.php" method="POST">
<input type="url" name="zrodlo" class="wyg_input"  autocomplete="off" required placeholder="Podaj link skąd wzięty został artykuł..."/>
<input type="url" name="image" class="wyg_input"  autocomplete="off" required placeholder="Podaj link do zdjęcia..."/>
<input type="text" name="login" class="wyg_input"  autocomplete="off" required placeholder="Podaj swój nick..."/>
<input type="text" name="temat" class="wyg_input" required autocomplete="off" placeholder="Podaj treść twojego tematu... "/>
<textarea name="tresc" class="wyg_text" rows="3" required autocomplete="off"  placeholder="Treść twojej wiadomości..."></textarea>
<button type="submit" class="btn_wyslij" name="wyslij">Wyślij wiadomość</button>
</form>
</body>
</html>';
if(isset($_POST['wyslij']) && !empty($_POST['zrodlo']) && !empty($_POST['image']) && !empty($_POST['login']) && !empty($_POST['tresc']) && !empty($_POST['temat']))
{
      
	
	$zrodlo = mysql_real_escape_string(htmlspecialchars($_POST['zrodlo']));
	$image = mysql_real_escape_string(htmlspecialchars($_POST['image']));
	$login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
	$tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
	$temat = mysql_real_escape_string(htmlspecialchars($_POST['temat']));
	$data = date('Y-m-d H:i:s');
	$ip = $_SERVER['REMOTE_ADDR'];
 
	
	mysql_query ("INSERT INTO `tematy` (`zrodlo`, `image`,`login`, `data`, `ip`, `tresc`, `temat`) VALUES('$zrodlo' ,'$image', '$login', '$data', '$ip', '$tresc', '$temat')");
 
	
	header('Location: '.$_SERVER['REQUEST_URI']);
}
    
else {
	
	$query = mysql_query ("SELECT * FROM `tematy` ORDER BY `tematy`.`data` DESC"); 
 
	
	echo '<div id="qt" >';

	
	while($shout=mysql_fetch_array($query)) { 
		echo '<div id="st" ><div id="pt">';
	
		echo"<a href='{$shout['zrodlo']}'</a>";
		echo "<img src='{$shout['image']}'/>"
	     .'<b id="autor"> '.'Autor: '.$shout['login'].'</b> ' .'</br>'
		 .'<h1 id="temat">'.$shout['temat'].'</h1> ' .'</br>'
	     .'<p id="art_tre">'.$shout['tresc'].'</p>'.'</br>'
	     .'<br/>'
		
	     .'Czas Napisania: '.$shout['data'] .'</br>'
	     .'</div></div>';
		
	}
 
	
	echo '</div>'; 
}
?>

 

strona na ktorej to jest pokazane http://www.ocena.log.ugu.pl/ lecz to nie dziala moglby ktos to poprawic zeby to dzalalo

0

Użyj debuggera i zobacz co masz pod zmienną div. Tam jest temat.php, a takiego elementu na stronie to chyba nie masz?

EDIT:

lecz to nie dziala moglby ktos to poprawic zeby to dzalalo

Sam możesz to poprawić. Wystarczy, że będziesz wiedział co piszesz.

0

nawet jesli dam #contener czy tez ?id=contener czy ? w action to dalej to samo sie dzieje dalem temat.php bo tak sie nazywal moj wczesniejszy plik a teraz nazywa sie index.php i dalej to samo pomoze ktos z tym zeby to zadzilalo bo nie mam pomyslu jak to zrobic

0

Dodaj do form atrybut np. data-dest='#contener i użyj go zamiast action w skrypcie js

0
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” />
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
</head>







<script>
$(document).ready(function() {
    $('form').submit(function(e) {
        e.preventDefault();
        div = $(this).attr("data-dest='#contener'");
        desc = $('textarea[name="tresc"]').val();
		 desc = $('input[name="zrodlo"]').val();
		 desc = $('input[name="image"]').val();
		 desc = $('input[name="login"]').val();
		 desc = $('input[name="temat"]').val();
        $(div).html(desc)
    });
});
</script>


<div id="contener">
wyswietlanie przeslanego formularza w tym divie 
</div>
<?php
echo'
<form data-dest=#contener method="POST">
<input type="url" name="zrodlo" class="wyg_input"  autocomplete="off" required placeholder="Podaj link skąd wzięty został 

artykuł..."/>
<input type="url" name="image" class="wyg_input"  autocomplete="off" required placeholder="Podaj link do zdjęcia..."/>
<input type="text" name="login" class="wyg_input"  autocomplete="off" required placeholder="Podaj swój nick..."/>
<input type="text" name="temat" class="wyg_input" required autocomplete="off" placeholder="Podaj treść twojego tematu... "/>
<textarea name="tresc" class="wyg_text" rows="3" required autocomplete="off"  placeholder="Treść twojej 

wiadomości..."></textarea>
<button type="submit" class="btn_wyslij" name="wyslij">Wyślij wiadomość</button>
</form>
</body>
</html>';
if(isset($_POST['wyslij']) && !empty($_POST['zrodlo']) && !empty($_POST['image']) && !empty($_POST['login']) && !empty

($_POST['tresc']) && !empty($_POST['temat']))
{
      
	
	$zrodlo = mysql_real_escape_string(htmlspecialchars($_POST['zrodlo']));
	$image = mysql_real_escape_string(htmlspecialchars($_POST['image']));
	$login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
	$tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
	$temat = mysql_real_escape_string(htmlspecialchars($_POST['temat']));
	$data = date('Y-m-d H:i:s');
	$ip = $_SERVER['REMOTE_ADDR'];
 
	
	mysql_query ("INSERT INTO `tematy` (`zrodlo`, `image`,`login`, `data`, `ip`, `tresc`, `temat`) VALUES('$zrodlo' 

,'$image', '$login', '$data', '$ip', '$tresc', '$temat')");
 
	
	header('Location: '.$_SERVER['REQUEST_URI']);
}
    
else {
	
	$query = mysql_query ("SELECT * FROM `tematy` ORDER BY `tematy`.`data` DESC"); 
 
	
	echo '<div id="qt" >';

	
	while($shout=mysql_fetch_array($query)) { 
		echo '<div id="st" ><div id="pt">';
	
		echo"<a href='{$shout['zrodlo']}'</a>";
		echo "<img src='{$shout['image']}'/>"
	     .'<b id="autor"> '.'Autor: '.$shout['login'].'</b> ' .'</br>'
		 .'<h1 id="temat">'.$shout['temat'].'</h1> ' .'</br>'
	     .'<p id="art_tre">'.$shout['tresc'].'</p>'.'</br>'
	     .'<br/>'
		
	     .'Czas Napisania: '.$shout['data'] .'</br>'
	     .'</div></div>';
		
	}
 

	echo '</div>'; 
}
?>

 

zrobilem to w ten sposob ale dalej nie dziala jesli usune <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script> to dziala ale nie wyswietla w dopowiednim divie tylko pod formularzem wiec nie wiem czy to dobrze zrobilem
wychodzi na to ze nie dziala przycisk wysij

1 użytkowników online, w tym zalogowanych: 0, gości: 1