0

我对此感到非常沮丧,我要疯了!如果您使用表单上的提交按钮,我有一个可以工作的表单。

我正在尝试将其放入模态 jqueryui 对话框中

因此,如果您删除 html 中的输入提交按钮,jqueryui 按钮将开始工作,但会破坏我的操作页面。

通常,操作页面会发送一封包含内容的电子邮件,然后重定向到感谢页面

这是它对 html 提交按钮所做的,但使用 jqueryui 按钮它会打印:

 Â 

并且不继续

这是初始化按钮的部分

 $( "#dialog-form" ).dialog({
  autoOpen: false,
  height: 400,
  width: 350,
  modal: true,
  buttons: {
    "Submit Request": function() {

   $("form[name='send']").submit()
   $('#send').submit();
      $(this).submit();
    $('#dialog-form').submit();

这是表格

<div id="dialog-form" title="Request a Quote">
<p class="validateTips">You are also welcome to call us at </p>

<form id="send" name="send" action="process.php" method="POST">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
<label for="number">Phone Number</label>
<input type="name" name="contact" id="number" value="" class="text ui-widget-content ui-corner-all" />
<label for="message">Message</label>
<textarea cols="49" rows="6"name="message"/></textarea>
 <input name="submit" type="submit" value="submit" >
</form>
 </div>

并将其添加到表单中使其工作

 <input name="submit" type="submit" value="Submit" />

但仅当您单击 html 表单提交按钮时

这是操作页面:

 <?php
 if(isset($_POST['submit'])) {
 $to = '@gmail.com' ;     //put your email address on which you want to receive the information
 $subject = 'Contact Form';   //set the subject of email.
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $message = "<table><tr><td>Name: </td><td>".$_POST['name']."</td></tr>
           <tr><td>E-Mail: </td><td>".$_POST['email']."</td></tr>
           <tr><td>Phone Number: </td><td>".$_POST['contact']."</td></tr>
           <tr><td>Message: </td><td>".$_POST['message']."</td>
           </tr></table>" ;
   mail($to, $subject, $message, $headers);
   header('Location: contact_thanks.php');
 }
 ?>

 

4

1 回答 1

0

我相信这可以用直接的 JavaScript 来完成;将表单的 id 设置为某种东西(在您的情况下,id="send"然后像这样调用Submit()事件:

document.forms["send"].submit(); 

其中方括号中的字符串是表单的id。另一种方法是使用表单的名称(在您的情况下也是“发送”):

<script type="text/javascript">
    function submitform()
    {
      document.send.submit(); <-- 'send' refers to your form name
    }
</script>

希望这对你有用!

改编自此处找到的代码。

编辑:问题:在您的原始 HTML 中,表单是否有结束标记?这可能会阻止找到整个表格。

于 2013-07-15T01:40:20.973 回答