Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Problem mit Kontaktfeld
#1
Hi, habe ein Problem mit einem Kontaktfeld, 
Fehler wird angezeigt: Something go wrong, please try again later
Wäre cool, wenn mir einer sagt, wo ich mich vertan habe....
Hier die Codierung:
 
contact-form.php
PHP-Code:
        <form id="contact" class="contact flex-form" method="post" action="javascript:void(null);" onsubmit="call()">
    <
class="text-underline font-22">Contact Form </b>    
     
   <div class="flex-form-row">
     
       <label >Name: *</label>
     
       <input id="name" name="name" type="text" required>
     
   </div>
     
   <div class="flex-form-row">
     
       <label >Email Address: *</label>
     
       <input type="email" id="email" name="email"  required>
     
   </div>
     
   <div class="flex-form-row">
     
       <label >Phone Number:</label>
     
       <input type="tel" id="phone" name="phone" >
     
   </div>
     
   <div class="flex-form-row">
     
       <label >Message: *</label>
     
       <textarea id="message" name="message" rows="5" required></textarea>
     
   </div>
     
   <div  class="flex-form-button">
     
       <input id="send" class="btn" name="submit" type="submit" value="Send">
     
   </div>
        <
b>* Mandatory Item  </b>
 
   </form>

 
   <script type="text/javascript" language="javascript">
 
        function call() {
 
          var msg   = $('#contact').serialize();           
            
$.ajax({
 
             type'POST',
 
             url'kontakt.php',
 
             datamsg,
 
             success: function(data) {
                 
 console.log(data);
                 
 if (data==true){
 
                   $('#contact').trigger'reset' );
                    
alert('Message successfully sent');
                 
 }
                 
 else {
                    
alert('Something go wrong, please try again later');
                 
 }    
 
             },
 
             error function(xhrstr){
 
               alert('Something go wrong, please try again later');
 
             }
 
           });
 
    
        
}
 
   </script> 

contact.php
PHP-Code:
<?php

require_once('framework.php');

class 
FrontController extends Controller {
    
    public function 
run() {
        
$action filter_input(INPUT_GET'action');
        
$method 'action' ucfirst($action);
        if(
method_exists($this$method)) {
            try {
                
header('Content-type: application/json'true200);
                echo 
json_encode([
                    
'result' => true,
                    
'data' => $this->$method(),
                ]);
            } catch(
Exception $exception) {
                
$code $exception->getCode() ?: 400;
                
header('Content-type: application/json'true$code);
                echo 
json_encode([
                    
'result' => false,
                    
'data' => [
                        
'message' => $exception->getMessage(),
                        
'code' => $code,
                        
'trace' => $exception->getTraceAsString(),
                    ],
                ]);
            }
        } else {
            try {
                echo 
$this->actionContact();
            } catch(
Exception $exception) {
                echo 
$exception->getMessage();
            }
        }
    }
    
    public function 
actionContact() {
        
$categoryId filter_input(INPUT_GET'category'FILTER_VALIDATE_INT);
        try {
            
$category $this->getCategoryModel()->getById($categoryId);
        } catch(
Exception $exception) {
            
$category $this->getCategoryModel()->getFirst();
        }
        
$paginator $this->getPaginator($category['id']);
        
$paginator->setPage(filter_input(INPUT_GET'page'FILTER_VALIDATE_INT));
        return 
$this->getView()->render('contact', [
            
'category' => $category,
            
'categories' => $this->getCategoryModel()->getList($categoryId),
            
'images' => $this->getImageModel()->getList($category['id'], $paginator$this->getUser()->isLoggedIn()),
            
'user' => $this->getUser(),
            
'paginator' => $paginator,
        ]);
    }

    public function 
actionList() {
        
$categoryId filter_input(INPUT_POST'category'FILTER_VALIDATE_INT);
        
$category $this->getCategoryModel()->getById($categoryId);
        
$paginator $this->getPaginator($category['id']);
        
$paginator->setPage(filter_input(INPUT_POST'page'FILTER_VALIDATE_INT));
        
$images $this->getImageModel()->getList($category['id'], $paginator$this->getUser()->isLoggedIn());
        return [
            
'html' => $this->getView()->render('list', [
                
'images' => $images,
                
'user' => $this->getUser(),
                
'paginator' => $paginator,
            ]),
            
'page' => $paginator->getPage(),
            
'offset' => $paginator->getOffset() + 1,
        ];
    }
    
    public function 
actionLogin() {
        
$username filter_input(INPUT_POST'username'FILTER_SANITIZE_STRING);
        
$password filter_input(INPUT_POST'password'FILTER_SANITIZE_STRING);
         return 
$this->getUser()->login($username$password);
    }
    
    public function 
actionLogout() {
        
$this->checkLoggedIn();
        return 
$this->getUser()->logout();
    }
    
}

$controller = new FrontController(require_once('config.php'));
$controller->run(); 

kontakt.php

PHP-Code:
<?php 

$recaptcha 
$_REQUEST['g-recaptcha-response'];
$secret '6LfJbgoUAAAAAEgkT-SdXYBTSJLGL5qiyQongZSK';
$url "https://www.google.com/recaptcha/api/siteverify?secret=".$secret ."&response=".$recaptcha."&remoteip=".$_SERVER['REMOTE_ADDR'];
$status 1;
if(!empty(
$recaptcha)) {
 
   $curl curl_init();
 
   if(!$curl) {
 
       $status 2   
} else {
 
   curl_setopt($curlCURLOPT_URL$url);
 
   curl_setopt($curlCURLOPT_RETURNTRANSFER1);
 
   curl_setopt($curlCURLOPT_TIMEOUT10);
 
   curl_setopt($curlCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
 
   $curlData curl_exec($curl);
 
   curl_close($curl);    
    $curlData 
json_decode($curlDatatrue);
 
   if($curlData['success']) {
 
       $status 0;
 
   }
 
 }

if(
$status === 0) {  
//Все хорошо
 
   $name $_POST['name'];
 
   $email $_POST['email'];
 
   $phone $_POST['phone'];
 
   $msg $_POST['message'];
 
   
    $subject 
'Contact us';
 
   $message 'Hello, my name is ' $name ". \r\n" ;
 
   $message .= $msg;
 
   if ($phone!='')
 
       $message .= "\r\n My phone " $phone ".\r\n";

 
   $headers "MIME-Version: 1.0" "\r\n";
 
   $headers .= "Content-type:text/html;charset=UTF-8" "\r\n";

 
   // More headers
 
   $headers .= 'From: <'$email'>' "\r\n";

 
   $result mail('info@email.de'$subject$message$headers);    
    echo json_encode
($result 0);
} else if(
$status === 1) {  
//Неверный код   
 
   echo json_encode(0);
} else if(
$status === 2) {  
//Ошибка CURL  
 
   echo json_encode(0);
}

 
   
?>
Zitieren
#2
Also, "cool" wäre mehr Infos anzugeben, als das ein Fehler angezeigt wird. Ich schätze, du wirst den code nicht selber geschrieben haben richtig? Die function die hier aufgerufen wird, um um dem Benutzer mitzuteilen das etwas schief gelaufen ist befindet sich im Code der contact-form.php. 

Zitat:<script type="text/javascript" language="javascript">
 
        function call() {
 
          var msg   = $('#contact').serialize();           
            
$.ajax({
 
             type'POST',
 
             url'kontakt.php',
 
             datamsg,
 
             success: function(data) {
                 
 console.log(data);
                 
 if (data==true){
 
                   $('#contact').trigger'reset' );
                    
alert('Message successfully sent');
                 
 }
                 
 else {
                    
alert('Something go wrong, please try again later');
                 
 }    
 
             },
 
             error function(xhrstr){
 
               alert('Something go wrong, please try again later');
 
             }
 
           });
 
    
        
}
 
   </script> 

Aber was ist schief gelaufen? Welche Wege bist du bisher gegangen? Was hast du bereits ausprobiert? Ich hab zwar keine Ahnung, und kann mir nicht vorstellen das in diesem Forum aktiv Leute posten, aber das würde wahrscheinlich helfen dein Problem zu lösen.
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste