[英]PHP passing form values to a popup window with javascript
I have a page with a form where a user enters details. 我有一个页面,用户可以在其中输入详细信息。 What I need to do is, when the user clicks the submit button of the form, a popup window appears that is passed all of the values of the form. 我需要做的是,当用户单击表单的提交按钮时,将出现一个弹出窗口,该窗口将传递表单的所有值。 index.php 的index.php
<?php
include "add_complain.php";
?>
<form action="" enctype="multipart/form-data" method="post" >
Add Cover Pic :<br>
<input name="cover_pic" type="file" id="cover_pic"/><br>
Article title :<br>
<textarea name="article-title" id="article-title" style="width: 100%">
</textarea><br>
Article body :<br>
<textarea name="article-body" id="article-body" style="height: 100px">
</textarea><br>
Choose Image :<br>
<input name="file[]" type="file" id="file"/>
<input type="button" id="add_more" class="upload" value="Add More Files"/><br><br>
Insert Embedded code for video :<br>
<input type="text" name="embedded_code"><br>
<input name="submit" type="button" id="submit" value="SUBMIT" onclick="popup();" /><br>
</form>
<script>
function popup()
{
$(".background_popup").show();
$("#modal").show();
}
</script>
add_complain.php add_complain.php
<div id="modal" class="popupContainer" style="display:none;">
<header class="popupHeader">
<span class="header_title">ADD COMPLIAN</span>
<span class="modal_close"><i class="fa fa-times"></i></span>
</header>
<section class="popupBody">
<div>//fetch form data
</div>
</section>
</div
This is my code.. im not able to fetch form values 这是我的代码.. im无法获取表单值
If you just want to display the data to your modal/popup, you can use jquery val() and jquery text() 如果只想将数据显示到模态/弹出窗口,则可以使用jQuery val()和jquery text()
Like this: 像这样:
<script>
//insert the following code to your popup function
//get the values from the form
var coverPic = $('#cover_pic').val();
var articleTitle = $('#article-title').val();
var articleBody = $('article-body').val();
//insert the values to your <p>'s
$('#coverPic').text(coverPic);
$('#articleTitle').text(articleTitle);
$('#articleBody').text(articleBody);
</script>
<!-- supposed to be your modal body -->
<div>
<p id='coverPic'></p>
<p id='articleTitle'></p>
<p id='articleBody'></p>
</div>
If you want to send it as a form data via AJAX use jquery serialize() 如果要通过AJAX将其作为表单数据发送,请使用jquery serialize()
You can refer to this: get All Form elements values using jquery? 您可以参考以下内容: 使用jquery获取所有Form元素值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.