Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wysylanie formularza do okreslonego diva na stronie, wysylanie za pomoca action
jaca121212
post 4.01.2015, 09:13:10
Post #1





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

Ostrzeżenie: (0%)
-----


witam mam taki problem mam formularz zrobiony i chcialbym zeby po kliknieciu wyslal on cala zawartosc do odpowiedniego diva
<form action="#contener" method="POST">
<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>
na stronie jest utworzony div o nazwie contener jak to powinno byc zeby to dzialalo
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
sf
post 4.01.2015, 09:38:16
Post #2





Grupa: Zarejestrowani
Postów: 1 597
Pomógł: 30
Dołączył: 19.02.2003
Skąd: Tychy

Ostrzeżenie: (0%)
-----


Bez przeładowania nie możesz tego zrobić w php tylko za pomocą javascript. Poniżej przyjkład z jquery.

Kod
<script type='text/javascript' src='jquery.min.js'></script>
<script>
$(document).ready(function() {
    $('form').submit(function(e) {
        e.preventDefault();
        div = $(this).attr('action');
        desc = $('textarea[name="tresc"]').val();
        $(div).html(desc)
    });
});
</script>

<div id="contener"></div>


Jeżeli chcesz użyć php to musisz ustawić w action plik php, który wyświetli odpowiedni kod html.

Ten post edytował sf 4.01.2015, 09:39:54


--------------------
Zapraszam na mój php blog, tworzenie stron.
Go to the top of the page
+Quote Post
jaca121212
post 4.01.2015, 10:09:39
Post #3





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

Ostrzeżenie: (0%)
-----


PO DODANIU TEGO KODY NIE DZIALA MI WYSYLANIE http://www.ocena.log.ugu.pl/ NIC SIE NIE POKAZUJE NA STRONIE POMOZECIE
poprawiony kod ktory nadal nie dziala pomoze ktos
  1. <head>
  2. <meta http-equiv=?Content-Type? content=?text/html; charset=utf-8? />
  3. <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  4. </head>
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. <script>
  13. $(document).ready(function() {
  14. $('form').submit(function(e) {
  15. e.preventDefault();
  16. div = $(this).attr("data-desc='#contener'");
  17. desc = $('textarea[name="tresc"]').val();
  18. desc = $('input[name="zrodlo"]').val();
  19. desc = $('input[name="image"]').val();
  20. desc = $('input[name="login"]').val();
  21. desc = $('input[name="temat"]').val();
  22. $(div).html(desc)
  23. });
  24. });
  25. </script>
  26.  
  27.  
  28. <div id="contener">
  29. wyswietlanie przeslanego formularza w tym divie
  30. </div>
  31. <?php
  32. <form data-dest=#contener method="POST">
  33. <input type="url" name="zrodlo" class="wyg_input" autocomplete="off" required placeholder="Podaj link skąd wzięty został
  34.  
  35. artykuł..."/>
  36. <input type="url" name="image" class="wyg_input" autocomplete="off" required placeholder="Podaj link do zdjęcia..."/>
  37. <input type="text" name="login" class="wyg_input" autocomplete="off" required placeholder="Podaj swój nick..."/>
  38. <input type="text" name="temat" class="wyg_input" required autocomplete="off" placeholder="Podaj treść twojego tematu... "/>
  39. <textarea name="tresc" class="wyg_text" rows="3" required autocomplete="off" placeholder="Treść twojej
  40.  
  41. wiadomości..."></textarea>
  42. <button type="submit" class="btn_wyslij" name="wyslij">Wyślij wiadomość</button>
  43. </form>
  44. </body>
  45. </html>';
  46. if(isset($_POST['wyslij']) && !empty($_POST['zrodlo']) && !empty($_POST['image']) && !empty($_POST['login']) && !empty
  47.  
  48. ($_POST['tresc']) && !empty($_POST['temat']))
  49. {
  50.  
  51.  
  52. $zrodlo = mysql_real_escape_string(htmlspecialchars($_POST['zrodlo']));
  53. $image = mysql_real_escape_string(htmlspecialchars($_POST['image']));
  54. $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
  55. $tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
  56. $temat = mysql_real_escape_string(htmlspecialchars($_POST['temat']));
  57. $data = date('Y-m-d H:i:s');
  58. $ip = $_SERVER['REMOTE_ADDR'];
  59.  
  60.  
  61. mysql_query ("INSERT INTO `tematy` (`zrodlo`, `image`,`login`, `data`, `ip`, `tresc`, `temat`) VALUES('$zrodlo'
  62.  
  63. ,'$image', '$login', '$data', '$ip', '$tresc', '$temat')");
  64.  
  65.  
  66. header('Location: '.$_SERVER['REQUEST_URI']);
  67. }
  68.  
  69. else {
  70.  
  71. $query = mysql_query ("SELECT * FROM `tematy` ORDER BY `tematy`.`data` DESC");
  72.  
  73.  
  74. echo '<div id="qt" >';
  75.  
  76.  
  77. while($shout=mysql_fetch_array($query)) {
  78. echo '<div id="st" ><div id="pt">';
  79.  
  80. echo"<a href='{$shout['zrodlo']}'</a>";
  81. echo "<img src='{$shout['image']}'/>"
  82. .'<b id="autor"> '.'Autor: '.$shout['login'].'</b> ' .'</br>'
  83. .'<h1 id="temat">'.$shout['temat'].'</h1> ' .'</br>'
  84. .'<p id="art_tre">'.$shout['tresc'].'</p>'.'</br>'
  85. .'<br/>'
  86.  
  87. .'Czas Napisania: '.$shout['data'] .'</br>'
  88. .'</div></div>';
  89.  
  90. }
  91.  
  92.  
  93. echo '</div>';
  94. }
  95. ?>
  96.  


Ten post edytował jaca121212 4.01.2015, 15:02:24
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 10:33