Mit Winkel-4 zum senden von Formular-Daten
Hi ich Baue mir ein WordPress-theme und ich contact form 7 plugin auf, aber ich kann nicht herausfinden, den richtigen Weg zum senden der Formular-Daten an das plugin.
hier ist mein post:
import {
Injectable
} from '@angular/core';
import {
HttpClient,
HttpHeaders
} from '@angular/common/http';
@Injectable()
export class FormsService {
constructor(private http: HttpClient) {}
postForm(url, form) {
return this.http.post(url, form, {
headers: new HttpHeaders().set('Content-Type', 'multipart/form-data'),
})
}
}
und das Bauteil, dass die Nutzung des Dienstes:
onSubmit() {
const fd = new FormData();
fd.append('your-name', this.name);
fd.append('your-email', this.email);
fd.append('your-message', this.message);
fd.append('your-subject', this.sumbject);
const url = `/wp-json/contact-form-7/v1/contact-forms/${this.form_id}/feedback`;
this.sendMsg.postForm(url, fd).subscribe(
data => {
console.log(data);
},
err => console.log({
error: err
})
)
this.submitted = true;
}
Zu diesem Zeitpunkt der server-Antwort, dass die Nachricht gesendet wurde, ok, aber wenn ich auf der WP-admin Seite, nicht des Feldes erhalten Sie die Werte.
Aber Wenn ich Postbote mit dieser url und Parameter die form funktioniert alles wie ich will.
Ich auch eine andere Lösung gefunden, die funktioniert, aber nicht die eckige Art und Weise, wie ich sein will.
die Lösung
onSubmit() {
const url = `/wp-json/contact-form-7/v1/contact-forms/${this.form_id}/feedback`;
this.submitted = true;
}
sendData(url) {
let XHR = new XMLHttpRequest();
const FD = new FormData();
FD.append('your-name', this.name);
FD.append('your-email', this.email);
FD.append('your-message', this.message);
FD.append('your-subject', this.subject);
//Define what happens on successful data submission
XHR.addEventListener('load', function(event) {
alert('Yeah! Data sent and response loaded.');
});
//Define what happens in case of error
XHR.addEventListener('error', function(event) {
alert('Oups! Something went wrong.');
});
//Set up our request
XHR.open('POST', url);
//Send our FormData object; HTTP headers are set automatically
XHR.send(FD);
}
InformationsquelleAutor efirvida | 2017-11-01
Du musst angemeldet sein, um einen Kommentar abzugeben.
Fand ich meine Lösung des Problems war auf die Header-Definitionen für meinen Dienst, der richtige Weg ist:
InformationsquelleAutor efirvida