我想將一個彈出框合併到我的項目中。它工作,直到我嘗試從JavaScript傳遞一個值到PHP腳本。我已經包含了一個鏈接到我使用的例子並鏈接到原始腳本。原始劇本略有改動。我有標有問題的區域---->問題在javascript和php之間傳遞值 - Popup PHP Javascript HTML
完整的腳本可以在這裏找到: http://www.webdeveloper.com/forum/showthread.php?279111-Contact-form-popup-window
工作示例可以在這裏找到: http://ilolo.ru/wd/contact_form/
我有以下在hello.html
<form id='form1' style='width: 1100px'>
<table>
<th>Email</th>
<th>Options</th>
<tr>
<td>
<input type='text' id='email1' size='25' value='[email protected]'>
</td>
<td><a id='1' href='#null' class='contactus'><img src= 'images/emailbutton.jpg' title='Email' border='0' height='24' width='24'></img></a>
</tr>
</table>
</form>
下面的js是我在html中引用的.js文件。 我使用以下,因爲我有多個表單。在我的例子中只顯示了一個表單。 下面的警報工作....顯示正確的電子郵件地址,當我點擊圖片鏈接在HTML。
function findCenter(obj) {
var deltaX = parseInt(obj.css('padding-left')),
deltaY = parseInt(obj.css('padding-top'));
obj.css('left', $(window).width()/2 - obj.width()/2 - deltaX + 'px').css('top', $(window).height()/2 - obj.height()/2 - deltaY + 'px');
}
$(document).ready(function() {
$('.contactus').click(function() {
var element = $(this);
var J = element.attr('id');
var email = document.getElementById('email'+J).value;
alert(email);
$('#result').html('<h3>Loading</h3>').css('display', 'block');
findCenter($('#result'));
$.get('email.php', function (data) {
$('#result').html(data);
findCenter($('#result'));
$('#snd').click(function() {
var subject = document.getElementById('subject').value;
var addy = document.getElementById('addy').value;
var comments = document.getElementById('comments').value;
$('#result').append('<br /><br /><div><i>Sending...</i></div>');
$.post('lbi_email.php',{mode: 'snd', subject: subject, addy: addy, comments: comments},function(data){
$('#result').html(data);
findCenter($('#result'));
});
});
});
});
});
email.php
低於此值是沒有得到通過JavaScript和輸入值= $電子郵件不正確寫入(我認爲)
<?php
include('connection.php');
function showForm(){
$email=$_POST[ 'email'];
echo '<form name="mf" id="mf" action="" method="post">
<h2>Send Email To Customer</h2><br />
<p><label>Address :</label><input type="text" size="35" name="addy" id="addy" value="'.$email.'"/></p>
<p><label>Subject : </label><input type="text" size="35" name="subject" id="subject" value=""/></p>
<label>Message:</label><textarea style="width: 100%;" cols="20" rows="10" id="comments" name="comments"></textarea>
<p><a href="#" class="btn" id="snd" name="snd"><img src="submitbutton.jpg" title="Submit Email" border="0" height="25" width="75"></img></a></p></form>';
}
function sndForm(){
/* here goes checking data and so on... then sending if everything 's good and sending done show message to the user*/
echo '<h3>Everything\'s cool.
<br />
<br />Viva Cuba!</h3>
<script type="text/javascript">
setTimeout(\'$("#result").fadeOut("fast")\',3000);
</script>';
}
/*---------------------------------------------------------------------*/
$mode=(!empty($_GET['mode']))?$_GET['mode']:$_POST['mode'];
switch($mode)
{
case 'snd':sndForm();break;
default: showForm();break;
}
?>
杜de,縮進你的代碼。像這樣幾乎不可讀。 – ceejayoz