フォーム データを php に投稿し、以下の応答を取得しています。この応答を、フォーム変数を設定して電子メールを送信するために使用できるものに変換するにはどうすればよいですか?
これは、process.php を呼び出してフォーム データを投稿するバックボーン コレクションです。
define([
'jquery',
'underscore',
'backbone',
'models/postModel'
], function($, _, Backbone, postModel){
var postForm = Backbone.Collection.extend({
model: postModel,
url: 'process.php',
sync: function(method, model, options) {
var postObj = {
'name': $('#cmName').val(),
'email': $('#cmEmail').val(),
'website': $('#cmWeb').val(),
'project': $('#cmProject input[type=radio]:checked').val(),
'message': $('#contactMessage').val()
}
method = 'create';
options.timeout = 100000;
options.contentType = "application/json",
options.dataType = "json";
options.cache = false;
options.data = JSON.stringify(postObj);
return Backbone.sync(method, model, options);
},
parse: function(response) {
if(response != null) {
if (typeof response.data !== 'undefined') {
this.result = response.data;
}
}
return this.result;
},
});
return new postForm;
});
backbone.js アプリからのフォーム投稿
{"name":"test","email":"test@test.com","website":"","project":"Web Development","message":"Testing."}
php からの応答
array(1) {
["{\"name\":\"test\",\"email\":\"test@test_com\",\"website\":\"\",\"project\":\"Web_Development\",\"message\":\"$_POST$_POST$_POST$_POST$_POST$_POST$_POST\"}"]=>
string(0) ""
}
これがphpファイルの始まりです:
<?php
parse_str(file_get_contents("php://input"),$_POST);
$_POST = var_dump($_POST);
//$name =
//$email =