Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][PHP][AJAX][JQUERY] Blad 405 The requested method POST is not allowed for the URL /ajax/index.html., Problem z formularzem kontaktowym PHP/AJAX/JQUERY blad 405
MrSeefeld
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 21.02.2010

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


Witam!

Poniewaz nie znam sie jeszcze zbyt dobrze na jquery a o php nie wiem wlasciwie nic - formularzow kontaktowych do stron szukam w internecie.
Dzis wygrzebalem cos dosc ciekawego - idealnie nadajacego sie do projektu nad ktorym akualnie pracuje:

Link do oryginalnego tutka

Wprowadzilem kilka zmian:
1. Dodalem element textarea - na tresc wiadomosci - oraz kod jquery sprawdzajacy czy jakas wiadomosc zostala w ogole wpisana.
3. Pozmienialem troche w stylach - usunalem pozycjonowanie absolutne, zmienilem polozenie ostrzezenia o bledzie w wypelnieniu formularza.
4. Zmianilem adresy email na ktore maja przychodzic wiadomosci z formularza- zgodnie z instrukcia zawarta w readme.txt

(The process.php file in /bin does need adjustment to send an email correctly. At a minimum, you need to change the $to, $email, $fromaddress, and $mail->From to get it to work )

I wszystko by bylo pieknie gdyby to dzialalo:]

Wyskakuje blad 405 Method Not Allowed
The requested method POST is not allowed for the URL /ajax/index.html.

Sprawdzanie formularza dziala poprawnie. Jednak w momencie w ktorym formularz jest komplenty i ma zostac przekazany do scryptu wykonawczego dzieje sie cos dla mnie nie zrozumialego.

plik html mozna podejrzec tutaj:

Link do strony na serwerze

kod JS (JQuery)
Kod
$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#CCC"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
        // validate and process form
        // first hide any error messages
    $('.error').hide();
        
      var name = $("input#name").val();
        if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
        var email = $("input#email").val();
        if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
    var phone = $("input#phone").val();
        if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
    var mess = $("textarea#mess").val();
        if (mess == "") {
      $("label#mess_error").show();
      $("textarea#mess").focus();
      return false;
    }
        
        var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone  +'&mess=' + mess;
        //alert (dataString);return false;
        
        $.ajax({
      type: "POST",
      url: "process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
    });
});
runOnLoad(function(){
  $("input#name").select().focus();
});


PHP
  1. <?php
  2. if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
  3. $name = stripslashes(strip_tags($_POST['name']));
  4. } else {$name = 'No name entered';}
  5. if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
  6. $email = stripslashes(strip_tags($_POST['email']));
  7. } else {$email = 'No email entered';}
  8. if ((isset($_POST['phone'])) && (strlen(trim($_POST['phone'])) > 0)) {
  9. $phone = stripslashes(strip_tags($_POST['phone']));
  10. } else {$phone = 'No phone entered';}
  11. if ((isset($_POST['mess'])) && (strlen(trim($_POST['mess'])) > 0)) {
  12. $mess = stripslashes(strip_tags($_POST['mess']));
  13. } else {$phone = 'No message entered';}
  14. ?>
  15. <html>
  16. <head>
  17. <style type="text/css">
  18. </style>
  19. </head>
  20. <body>
  21. <table width="550" border="1" cellspacing="2" cellpadding="2">
  22. <tr bgcolor="#eeffee">
  23. <td>Name</td>
  24. <td><?=$name;?></td>
  25. </tr>
  26. <tr bgcolor="#eeeeff">
  27. <td>Email</td>
  28. <td><?=$email;?></td>
  29. </tr>
  30. <tr bgcolor="#eeffee">
  31. <td>Phone</td>
  32. <td><?=$phone;?></td>
  33. </tr>
  34. <tr bgcolor="#eeffee">
  35. <td>Message</td>
  36. <td><?=$mess;?></td>
  37. </tr>
  38. </table>
  39. </body>
  40. </html>
  41. <?
  42. $body = ob_get_contents();
  43.  
  44. $to = 'xxx@yyyy';
  45. $email = 'zzz@yyyy';
  46. $fromaddress = "aaa@bbbb";
  47. $fromname = "Online Contact";
  48.  
  49. require("phpmailer.php");
  50.  
  51. $mail = new PHPMailer();
  52.  
  53. $mail->From = "xxx@yyyy";
  54. $mail->FromName = "Contact Form";
  55. $mail->AddAddress("email_address@example.com","Name 1");
  56. $mail->AddAddress("another_address@example.com","Name 2");
  57.  
  58. $mail->WordWrap = 50;
  59. $mail->IsHTML(true);
  60.  
  61. $mail->Subject = "Demo Form: Contact form submitted";
  62. $mail->Body = $body;
  63. $mail->AltBody = "This is the text-only body";
  64.  
  65. if(!$mail->Send()) {
  66. $recipient = 'your_email@example.com';
  67. $subject = 'Contact form failed';
  68. $content = $body;
  69. mail($recipient, $subject, $content, "From: mail@yourdomain.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
  70. }
  71. ?>


Oprocz tych 3 - formularz posiada phpmailer oraz scrypt runonload.js

Probowalem odniesc sie do oryginalu - zmieniajac tylko adres maila w miejscu podanym w instrukcji - co prawda blad nie wyskakuje - pokazuje sie informacja o wyslalej wiadomosci -ale sam mail nigdy nie dociera.

W momencie kiedy zmieniam wartosc ktorej nie powinienem (zgodnie z instrukcja podana przez autora) mail dociera ale w postaci kolorowej ramki ktora tworzy plik wykonawczy php.
Link do funkcjonalnego oryginalu - ale bez pola textarea

Przesiedzialem juz nad tym dzis kilka godzin i najwyrazniej niz z mojej wiedzy juz nie wydoje:]
Jezeli macie chwilke bylbym ogromnie wdzieczny za jakies sugestie.

pozdrawiam, Piotrek

Ten post edytował thek 31.03.2010, 22:19:16
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 22.08.2025 - 16:00