簡體   English   中英

控制器中的表單發布變量

[英]form post variables in controller

這是我的javascript視圖,控制器正在調用。 javascript

$('#contact').submit(function(e){
e.preventDefault();
var name= $('input[name=contactname]').val();
var email= $('input[name=contactemail]').val();
var message= $('textarea[name=message]').val();
$.post("index.php/homepage/sendMail",{name:name, email:email, message:message},
function(){
   $('#contactUsMask').hide();
   $('#contactAckMask').show();
   });
});

控制者

$from = $_POST['email'];
$msg = $_POST['message'];
$name = $_POST['name'];

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);
$this->email->from($from, $name);
$this->email->to($to);
$this->email->subject($sub);
$this->email->message($msg);
if($this->email->send())
{
    return true;
}
else
{
    echo $this->email->print_debugger();
    return false;
}

我無法讀取帖子變量,請幫忙。 所有的努力表示贊賞

嘗試在您的帖子請求中使用$("#testform").serialize()

$('#contact').submit(function(e){
e.preventDefault();
$.post("index.php/homepage/sendMail",$("#contact").serialize(),
function(){
   $('#contactUsMask').hide();
   $('#contactAckMask').show();
   });
});

在您的控制器中,您將必須使用$this->input->post('email'); 獲取電子郵件值..,正如他們所說,嘗試執行var_dump($_POST)

如果您正在執行此跨站點,則會遇到跨站點問題,因為.post是$ .ajax的包裝器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM