I used this script (https://www.webslesson.info/2020/02/instant-search-with-pagination-in-php-mysql-jquery-and-ajax.html) and I would like to add a form to directly access a page number.
I tried this but it doesn't work !
<div class="goto-page">
<form action="" method="POST" onsubmit="return pageValidation()">
<input type="submit" class="goto-button" value="Go to page">
<input type="text"
class="enter-page-no" maxlength="4" size="3"
name="goto" min="1"
required >
</form>
</div>
PHP Code modified
if (isset($_POST['goto'])) {
$start = (($_POST['page'] - 1) * $limit);
$page = $_POST['goto'];
}
else
{
if($_POST['page'] > 1)
{
$start = (($_POST['page'] - 1) * $limit);
$page = $_POST['page'];
}
else
{
$start = 0;
}
}
Consider the following example. This expands on the jQuery already in use in the example you linked to.
$(function() {
function load_data(page, query = '') {
$.ajax({
url: "fetch.php",
method: "POST",
data: {
page: page,
query: query
},
success: function(data) {
$('#dynamic_content').html(data);
}
});
}
load_data(1);
$(document).on('click', '.page-link', function() {
var page = $(this).data('page_number');
var query = $('#search_box').val();
load_data(page, query);
});
$('#search_box').keyup(function() {
var query = $('#search_box').val();
load_data(1, query);
});
$(".goto-page form").submit(function(evt) {
evt.preventDefault();
load_data(parseInt($(".goto-page input[name='goto']").val()));
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<br />
<div class="container">
<h3 align="center">Live Data Search with Pagination in PHP Mysql using Ajax</h3>
<br />
<div class="card">
<div class="card-header">Dynamic Data</div>
<div class="card-body">
<div class="form-group">
<input type="text" name="search_box" id="search_box" class="form-control" placeholder="Type your search query here" />
</div>
<div class="table-responsive" id="dynamic_content">
</div>
<div class="goto-page">
<form>
<button type="submit">Go To Page</button>
<input type="text" class="enter-page-no" maxlength="4" size="3" name="goto" value="1" required>
</form>
</div>
</div>
</div>
</div>
When Enter is hit or the Button pressed, the form is submitted. The submit callback will gather the value and use load_data() to load that page.
Related
I have 3 query records in a database table of the same user. When I do query returns and shows the most recent query of the database table.
I want to return the 3 queries, always show the most recent query, but have a button that when clicked close the query that is showing and open the previous query and so on until no further queries.
In this way I always have access to the information registered in each consultation about the user.
At this point I return the query as follows:
<a name="view2" id="<?php echo $row["Id"]; ?>" data-toggle="modal" href="#dataModal1" class="btn btn-primary view_data2" />EGA</a>
<div id="dataModal1" class="modal fade" style="width:1000px;">
<div class="modal-dialog" style="width:1000px;">
<div class="modal-content" style="width:1000px;">
<div class="modal-header" style="width:1000px;">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><strong>Estado Geral e Autonomia</strong></h4>
</div>
<div class="container"></div>
<div class="modal-body" id="employee_detail1">
</div>
<div class="modal-footer">
Sair
</div>
</div>
</div>
</div>
$(document).on('click', '.view_data2', function() {
var employee_id1 = $(this).attr("Id");
if (employee_id1 != '') {
$.ajax({
url: "./select2",
method: "POST",
data: {
employee_id1: employee_id1
},
success: function(data) {
console.log(data);
$('#employee_detail1').html(data);
$('#dataModal1').modal('show');
}
});
}
});
on the select2 page I have the following code:
if(isset($_POST["employee_id1"]))
{
$output = '';
$query = "SELECT * FROM centrodb.PsicUtentes WHERE centrodb.PsicUtentes.Id = '".$_POST["employee_id1"]."'";
$result = mysqli_query($conn, $query);
$output;
while($row = mysqli_fetch_array($result))
{
$output .= '
<h4 class="modal-title">Identificação do Utente</h4>
<form method="post" id="insert_form2">
<fieldset class="grupo">
<table class="campo" cellspacing="10">
<tr>
<td>
<label>Data</label>
<input type="text" id="Data1" name="Data" class="form-control" value="'.$row["Data"].'" style="width:150px;" />
</td>
<td>
<label>Código Utente</label>
<input type="number" id="CodigoUtente1" name="CodigoUtente" value="'.$row["CodigoUtente"].'" class="form-control" style="width:100px;"/>
</td>
<td>
<label>Nome Utente</label>
<input type="text" id="Nome1" name="Nome" value="'.$row["Nome"].'" class="form-control" class="form-control" style="width:400px;"/>
</td>
<td>
<label>Data Nascimento</label>
<input type="date" id="DataNasc1" name="DataNasc" value="'.$row["DataNasc"].'" class="form-control" style="width:150px;"/>
</td>
</tr>
</table>
</fieldset>
</form>
';
}
$output;
echo $output;
}
I will show the image with the page when I have three queries:
I intended to have a button like the one surrounded in red and whenever I clicked, I closed the information of the query that is showing and opened the previous query.
Solution I'm trying.
<script type="text/javascript">
$(document).ready(function(){
$('.conteudo').hide();
$('.exibir').each(function(i){
$(this).click(function(){
$('.conteudo').each(function(j){
if(i == j) $(this).show('slow');
});
});
});
$('.ocultar').each(function(i){
$(this).click(function(){
$('.conteudo').each(function(j){
if(i == j) $(this).hide('slow');
});
});
});
});
</script>
if(isset($_POST["employee_id1"]))
{
$output = '';
$query = "SELECT * FROM centrodb.PsicUtentes WHERE centrodb.PsicUtentes.Id = '".$_POST["employee_id1"]."'";
$result = mysqli_query($conn, $query);
$output;
while($row = mysqli_fetch_array($result))
{
$output .= '
<h4 class="modal-title">Identificação do Utente</h4>
<div>
<a class="exibir" href="#">Ver</a>--
Ocultar
</div>
<div class="conteudo">
<form method="post" id="insert_form2">
<fieldset class="grupo">
<table class="campo" cellspacing="10">
<tr>
<td>
<label>Data</label>
<input type="text" id="Data1" name="Data" class="form-control" value="'.$row["Data"].'" style="width:150px;" />
</td>
<td>
<label>Código Utente</label>
<input type="number" id="CodigoUtente1" name="CodigoUtente" value="'.$row["CodigoUtente"].'" class="form-control" style="width:100px;"/>
</td>
<td>
<label>Nome Utente</label>
<input type="text" id="Nome1" name="Nome" value="'.$row["Nome"].'" class="form-control" class="form-control" style="width:400px;"/>
</td>
<td>
<label>Data Nascimento</label>
<input type="date" id="DataNasc1" name="DataNasc" value="'.$row["DataNasc"].'" class="form-control" style="width:150px;"/>
</td>
</tr>
</table>
</fieldset>
</form>
<div>
';
}
$output;
echo $output;
}
That's how it works, but I still wanted to make one thing better. I see the first record, but when I see the second the first is always open and should hide when I open the second. The second record opens when I click on view and hides when I click hide.
Also I wanted the Edit and New button, always according to the div that I open and in my project if there are two registry open the two buttons at the beginning of the project and should open as I open the div, I show in the image:
When I open the first time the:
enter image description here
When I see the first record:
enter image description here
When I see the second record:
enter image description here
Hi what you can do is hide your modal in your html content, and fill it with your ajax then once you have the data you can display it ,you can do it this way:
your php script:
if (isset($_POST["action"])) {
$action = $_POST["action"];
switch ($action) {
case 'SLC':
if (isset($_POST["id"])) {
$id = $_POST["id"];
if (is_int($id)) {
$query = "select * from client where clientId = '$id' ";
$update = mysqli_query($mysqli, $query);
$response = array();
while($row = mysqli_fetch_array($update)){
.......
// you need to fill the response array here with the info you
//want to display and send it with json encode later
}
echo json_encode($response);
}
}
break;
}
}
Where action can be a command you want to do SLC, UPD, DEL etc and id is a parameter
then in your ajax:
function getInfo(id) {
return $.ajax({
type: "POST",
url: "getInfo.php",
data: { action: "SLC", id:id }
})
}
then call it like this:
getInfo(id).done(function(response){
var data=JSON.parse(response);
if (data != null) {
$('#form_id').trigger("reset");
//fill your modal form using your data and display the modal after reset the form
$("#modal").show();
}
})
Hope it helps
I want to validate my form's input with database, so when user type on form's input and contain email already in use or exists it will display an alert and cant submit. I use CodeIgniter framework and jQuery.
I've tried using the code below to check if name exists and this could work. But when I apply it to the other case for email, it doesn't work and display message "The URI you submitted has disallowed characters."
How is the correct way to fix this?
View (kasir_halaman.php) :
<div id="addModal" class="modal fade" role="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title"><span class="glyphicon glyphicon-plus"></span> Tambah Kasir</h3>
</div>
<div class="modal-body">
<form action="<?php echo site_url('admin/kasir/addpetugas'); ?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Nama</label>
<input type="text" id="nama" name="nama" class="form-control" maxlength="100" required>
</div>
<div class="form-group">
<label>E-mail</label>
<input type="email" id="email" name="email" class="form-control" maxlength="150" required>
</div>
<div class="form-group">
<label>Kategori</label>
<select class="form-control" name="kategoripetugas" required>
<option value=""> -- Pilih Kategori -- </option>
<option value="1">Admin</option>
<option value="2">Kasir</option>
</select>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" maxlength="30">
</div>
<div class="form-group">
<label>Ulangi Password</label>
<input type="password" name="confirmpassword" class="form-control" maxlength="30">
</div>
<button type="submit" class="btn btn-primary" style="width:100%;">Tambah</button>
</form>
</div>
</div>
</div>
</div>
Controller (kasir.php) :
public function cekData($table, $field, $data)
{
$match = $this->Crud->read($table, array($field=>$data), null, null);
if($match->num_rows() > 0){
$report = 2;
}else{
$report = 1;
}
echo $report;
}
public function register_email_exists()
{
if (array_key_exists('email',$_POST)) {
if ($this->Crud->email_exists($this->input->post('email')) == TRUE ) {
echo false;
} else {
echo true;
}
}
}
Model (Crud.php) :
function email_exists($email)
{
$this->db->where('email', $email);
$query = $this->db->get('petugas');
if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
}
jQuery AJAX (petugas.js) :
$(document).ready(function(){
var check1=0; var id;
$("#nama").bind("keyup change", function(){
var nama = $(this).val();
$.ajax({
url:'kasir/cekData/petugas/nama/'+nama,
data:{send:true},
success:function(data){
if(data==1){
$("#report1").text("");
check1=1;
}else{
$("#report1").text("*nama petugas sudah terpakai");
check1=0;
}
}
});
});
var check2=0;
$("#email").bind("keyup change", function(){
//var email = $(this).val();
$.ajax({
url:'kasir/register_email_exists',
data:{send:true},
success:function(data){
if(data==1){
$("#report2").text("");
check2=1;
}else{
$("#report2").text("*email sudah terpakai");
check2=0;
}
}
});
});
var check4=0;
$("#confirmpassword").bind("keyup change", function(){
var password = $("#password").val();
var confirmpassword = $(this).val();
if (password == confirmpassword){
$("#report4").text("");
check4=1;
}else{
$("#report4").text("*Password tidak sama");
check4=0;
}
});
$("#submit").click(function(event){
if(check1==0){
event.preventDefault();
}
if(check4==0){
event.preventDefault();
}
});
});
Use ajax post method instead and take data at php side from POST request
you can check more about jquery ajax here: http://api.jquery.com/jquery.post/
and about php post here: http://php.net/manual/en/reserved.variables.post.php
//JS
$("#email").bind("keyup change", function(){
var email = $(this).val();
$.ajax({
url:'kasir/register_email_exists',
type: "POST",// <---- ADD this to mention that your ajax is post
data:{ send:true, email:email },// <-- ADD email here as pram to be submitted
success:function(data){
if(data==1){
$("#report2").text("");
check2=1;
}else{
$("#report2").text("*email sudah terpakai");
check2=0;
}
}
});
});
// PHP
// At php side take your data from $_POST
$send = $_POST['send'];
$email = $_POST['email'];
...
While inserting Data into MySQL using Ajax and PHP, taking limited data from rich textarea,Is there any problem?
JQuery Script
$('#adddesc').click(function(e)
{
e.preventDefault();
var txtcategoryname=tinyMCE.get('txtcategoryname').getContent();
var txttitle=$('#txttitle').val();
var selectError1=$("#selectError1").val();
var selectError2=$("#selectError2").val();
var selectError3=$("#selectError3").val();
//var fimage=$("#fimage").val();
//alert($("#selectError2").val().length);
var dataString;
var err;
err=(txttitle!='' && txtcategoryname!='' && $("#selectError1").val()!='0' && $("#selectError2").val()!='0' && $("#selectError3").val()!='0')?'0':'1';
// var dataString1="txttitle="+txttitle+"& description="+txtcategoryname+"& catname="+selectError1+"& tags="+selectError2;
//dataString1="txttitle="+txttitle+"& description="+txtcategoryname+"& catname="+selectError1+"& tags="+selectError2+"& subcat="+selectError3;
// alert(dataString1);
if(err=='0')
{
dataString="txttitle="+txttitle+"& description="+txtcategoryname+"& catname="+selectError1+"& tags="+selectError2+"& subcat="+selectError3;
//alert(dataString);
$.ajax({
type: "POST",
url: "aAddDescription.php",
data: dataString,
cache: true,
beforeSend: function(){ $("#adddesc").val('Adding Des.....');},
success: function(html){
//$("#txtcategoryname").val('');
tinyMCE.get('txtcategoryname').setContent('');
$("#txttitle").val('');
//$("#selectError1").get(0).selectedIndex = 0;
//$("#error").removeClass("alert alert-error");
$("#error").addClass("alert alert-success");
$("#error").html("<span style='color:#cc0000'>Success:</span> Description Added Successfully. ").fadeIn().delay(3000).fadeOut();
}
});
HTML Form script
<form class="form-horizontal" method="POST" action="" enctype="multipart/form-data" autocomplete="off">
<fieldset>
<div class="control-group">
<label class="control-label" for="selectError">Select Cateogry</label>
<div class="controls">
<?php
$result=mysqli_query($db,"SELECT * FROM categories ");
//$count=mysqli_num_rows($result);
$op="<option value='0'>Select Category</option>";
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$op.="<option value='".$row['id']."'>".$row['title']."</option>";
}
?>
<select id="selectError1" >
<?php echo $op; ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="selectError">Select Sub Cateogry</label>
<div class="controls">
<select id="selectError3">
<option selected="selected" value="0">--Select Sub--</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="focusedInput">Enter Title:: </label>
<div class="controls">
<input class="form-control" type="text" id="txttitle" name="txttitle" value="" placeholder="Enter Title"><span id="user-availability-status"></span> <img src="LoaderIcon.gif" id="loaderIcon" style="display:none;width:20px;height:20px;" />
</div></div>
<div class="control-group">
<textarea rows="10" cols="20" name="content" style="width:100%; height:150px" id="txtcategoryname"></textarea>
</div>
<div class="control-group">
<label class="control-label" for="selectError1">Tags(select All with Press Ctrl)</label>
<div class="controls">
<?php
$result=mysqli_query($db,"SELECT * FROM tags ");
//$count=mysqli_num_rows($result);
$op1='';
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$op1.="<option value='".$row['title']."'>".$row['title']."</option>";
}
?>
<select id="selectError2" multiple >
<?php //echo $op1; ?>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" id="adddesc">Save changes</button>
<button class="btn">Cancel</button>
</div>
</fieldset>
</form>
aAddDescription.php
<?php
include("common/db.php");
session_start();
if(isSet($_POST['description']) && isSet($_POST['txttitle']))
{
// username and password sent from Form
$description=$_POST['description'];
$txttitle=mysqli_real_escape_string($db,$_POST['txttitle']);
$catname=mysqli_real_escape_string($db,$_POST['catname']);
$subcat=mysqli_real_escape_string($db,$_POST['subcat']);
$tags=mysqli_real_escape_string($db,$_POST['tags']);
//$fimage=$_FILES['fimage']['name'] ;
$cby=$_SESSION['login_user'];
//$result=mysqli_query($db,"SELECT * FROM categories WHERE title='$categoryname'");
//$count=mysqli_num_rows($result);
//$target_dir = "uploads/";
//$target_file = $target_dir.$_FILES['fimage']['name'];
//move_uploaded_file($_FILES['fimage']['tmp_name'],$target_file);
//$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
// If result matched $myusername and $mypassword, table row must be 1 row
/*if($count>0)
{
echo "0";
}
else
{
mysqli_query($db,"INSERT INTO categories(title) VALUES('".$categoryname."')");
echo "1";
}*/
//date_default_timezone_set('Asia/Delhi');
mysqli_query($db,"INSERT INTO description(title,description,cat_id,tags_id,created,modified,createdby,modifiedby,subcat_id) VALUES('".$txttitle."','".$description."','".$catname."','".$tags."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','".$cby."','".$cby."','".$subcat."')");
$cid=mysqli_insert_id($db);
$cresult=mysqli_query($db,"SELECT * FROM counter WHERE cont_id='$cid'");
$ccount=mysqli_num_rows($cresult);
if($ccount==0)
{
mysqli_query($db,"INSERT INTO counter(cont_id) VALUES(".$cid.")");
}
echo "1";
}
?>
Please help me any thing wrong in this code?...even i changed cache to false also getting same problem. if i type 1000/less or more lines data, always it is taking limited data. Please help me. thanks in Advance
I'd be willing to bet that your text has characters in it that are interfering with the url like "&", "?", "/", "=", etc.
You should encode your text with encodeURIComponent() like this:
var txtcategoryname=encodeURIComponent(tinyMCE.get('txtcategoryname').getContent());
var txttitle=encodeURIComponent($('#txttitle').val());
var selectError1=encodeURIComponent($("#selectError1").val());
var selectError2=encodeURIComponent($("#selectError2").val());
var selectError3=encodeURIComponent($("#selectError3").val());
I have this script that allows me to send data to the database without reloading the page. The form data is sent to file process.php.
At the end of the process, inside the div box of the form is printed a notice that everything went ok
<script type="text/javascript">
$(document).ready(function(){
$(document).on('submit', '.formValidation', function(){
var data = $(this).serialize();
$.ajax({
type : 'POST',
url : 'submit.php',
data : data,
success : function(data){
$(".formValidation").fadeOut(500).hide(function(){
$(".result").fadeIn(500).show(function(){
$(".result").html(data);
});
});
}
});
return false;
});
});
</script>
Page success.php:
foreach( $_POST as $key => $value ) {
$sql = "INSERT INTO tbl_".$key."(nome_".$key.") VALUES ('$value')";
$result = dbQuery($sql);
}
print "ok";
And the div box for the notice <div class="result"></div>
The problem: I have many div box with a form and when I print the notice of success, it happen into all the <div>, because the call notification is always .result
success: function(data){
$(".formValidation").fadeOut(500).hide(function(){
$(".result").fadeIn(500).show(function(){
$(".result").html(data);
});
});
}
What I want: Print the success notice in its own div depending on the form that I sent.
Thanks
EDIT: The html interested
<form id="myform2" class="formValidation" name="myform2" action="" method="post"></form> <!-- this is the form for the <div> in html5 -->
<div class="widget-body">
<div class="widget-main">
<div>
<label for="form-field-select-1">Comune</label>
<select name="comune" class="form-control" id="form-field-select-1" form="myform2">
<option value="">Seleziona...</option>
<?php
$comune = "SELECT * FROM tbl_comune ORDER BY nome_comune ASC";
$result_comune = dbQuery($comune);
if (dbNumRows($result_comune) > 0) {
while($row_comune = dbFetchAssoc($result_comune)) {
extract($row_comune);
?>
<option value="<?php echo $id_comune; ?>"><?php echo $nome_comune; ?></option>
<?php
}
} else {
?>
<option value="">Non ci sono dati</option>
<?php
}
?>
</select>
</div>
<hr>
<div class="widget-body">
<div class="widget-main">
<div>
<input type="text" name="comune" id="comune" value="" placeholder="Aggiungi Comune" form="myform2">
<input type="submit" name="submit" value="Submit" class="btn btn-sm btn-success" form="myform2">
<div class="result"></div>
</div>
</div>
</div>
</div>
</div>
If the form is in a div and the result is next to the form, you can do sibling:
$form.next(".result").html(data);
or elsewhere in the same parent:
$form.parent().find(".result").html(data);
or in your case
$form.find(".result").html(data);
Like this - note I have removed all the unnecessary hiding.
$(function() {
$(document).on('submit', '.formValidation', function(e) {
e.preventDefault();
var data = $(this).serialize();
$form = $(this); // save a pointer to THIS form
$result = $form.find(".result");
$.ajax({
type: 'POST',
url: 'submit.php',
data: data,
success: function(data) {
$result.html(data);
$form.fadeOut(500, function() {
$result.fadeIn(500)
});
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="myform2" class="formValidation" name="myform2" action="" method="post"></form>
<!-- this is the form for the <div> in html5 -->
<div class="widget-body">
<div class="widget-main">
<div>
<label for="form-field-select-1">Comune</label>
<select name="comune" class="form-control" id="form-field-select-1" form="myform2">
<option value="">Seleziona...</option>
</select>
</div>
<hr>
<div class="widget-body">
<div class="widget-main">
<div>
<input type="text" name="comune" id="comune" value="" placeholder="Aggiungi Comune" form="myform2">
<input type="submit" name="submit" value="Submit" class="btn btn-sm btn-success" form="myform2">
<div class="result"></div>
</div>
</div>
</div>
</div>
</div>
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm not very good at jQuery. I have to show a form in the code below, but it seems jquery (or Javascript) keeps the code hidden.
The sample output is inhttp://210.48.94.218/~printabl/products/business-cards/. If you click the "CONTINUE" button in the page.
<?php
/**
* Template Name: Contact Page
*
* Description: Twenty Twelve loves the no-sidebar look as much as
* you do. Use this page template to remove the sidebar from any page.
*
* Tip: to remove the sidebar from all posts and pages simply remove
* any active widgets from the Main Sidebar area, and the sidebar will
* disappear everywhere.
*
* #package WordPress
* #subpackage Twenty_Twelve
* #since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<script type="text/javascript">
var x1 = 5;
var x2 = 10;
var value = x1 * x2;
var list_value = 1;
var size, fold, back, front, qlnt, qlt, tprice;
</script>
<div id="jdModal">
<div id="jdModalContent" style="padding:10px;background:#fff;">
<form id="product_form" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data">
<input type="hidden" name="size" value="0" />
<input type="hidden" name="fold" value="0" />
<input type="hidden" name="back" value="0" />
<input type="hidden" name="front" value="0" />
<input type="hidden" name="qlnt" value="0" />
<input type="hidden" name="qlt" value="0" />
<input type="hidden" name="tprice" value="0" />
<input type="hidden" name="productName" value="Business Card" />
<h2>CONTACT US</h2>
<div><label>Business Name*</label><input type="text" name="businessName" value="" /></div>
<div><label>Your Name*</label><input type="text" name="yourName" value="" /></div>
<div><label>Email*</label><input type="text" name="yourEmail" value="" /></div>
<div><label>Phone*</label><input type="text" name="yourPhone" value="" /></div>
<div><label>Delivery Region*</label><input type="text" name="deliveryRegion" value="Christchurch" /></div>
<div><label>Employees</label><input type="text" name="employees" value="1-5 staff members in my business" /></div>
<div><label> </label><p class="note">If required please upload your files here (2 MB max).</p></div>
<div style="position:relative"><label>Upload file</label><input type="hidden" value="" id="jd_upload_uri_1" name="jd_upload_uri_1" /><input type="text" class="jd_upload_filename" name="jd_upload_file_1" readonly="readonly" /><input type="button" class="jd_upload" id="jd_upfile_1"value="Browse ..." />
</div>
<div style="position:relative"><label>Upload file</label><input type="hidden" value="" id="jd_upload_uri_2" name="jd_upload_uri_2" /><input type="text" class="jd_upload_filename" name="jd_upload_file_2" readonly="readonly" /><input type="button" class="jd_upload" id="jd_upfile_2" value="Browse ..." />
</div>
<div style="position:relative"><label>Upload file</label><input type="hidden" value="" id="jd_upload_uri_3" name="jd_upload_uri_3" /><input type="text" class="jd_upload_filename" name="jd_upload_file_3" readonly="readonly" /><input type="button" class="jd_upload" id="jd_upfile_3" value="Browse ..." />
</div>
<div><label>Message</label><textarea name="msg"></textarea></div>
<div><label>I'm also interested in</label><p><input type="checkbox" name="interests[]" value="Business Cards" /><span>Business Cards</span><input type="checkbox" name="interests[]" value="Flyer" /><span>Flyer</span></p></div>
<div style="margin-bottom:15px"><label> </label><p><input type="checkbox" name="interests[]" value="Booklets" /><span>Booklets</span><input type="checkbox" name="interests[]" value="Postcards" /><span>Postcards</span></p></div>
<div><label> </label><p class="note">To help us fight spam, please type the characters you see below.</p></div>
<div class="captcha_fix"><label> </label><p style="text-align:right"><input type="submit" value=" " name="productOrderForm" class="submit-product" /><input type="text" name="jd_captcha" class="jd_captcha" value="" maxlength="6" /><img src="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php?captcha" class="jd_captcha_img" /></p></div><div id="jd_msg_box"><p class="text"></p></div>
<div style="clear:both"></div>
</form>
</div>
</div>
<iframe name="formFrame" id="formFrame" src="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php?load"></iframe>
<div id="file-upload-elem">
<form id="upload_form_1" class="uploader-box uploader-box-1" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data"><input type="file" name="upload_file_1" class="inp-file" id="upload_file_1" /></form>
<form id="upload_form_2" class="uploader-box uploader-box-2" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data"><input type="file" name="upload_file_2" class="inp-file" id="upload_file_2" /></form>
<form id="upload_form_3" class="uploader-box uploader-box-3" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data"><input type="file" name="upload_file_3" class="inp-file" id="upload_file_3" /></form>
</div>
<script type="text/javascript">
var fileUploadElem = jQuery("#file-upload-elem").html();
jQuery("#file-upload-elem").remove();
var insertUpload, jd_error, jd_success, upload_error, jd_show_msg, invalid_captcha;
var isCustomQuote = false;
jQuery(function() {
console.log("Test");
if(jQuery("#customs").length > 0 || jQuery("#frprice").length > 0) {
jQuery("body").append(fileUploadElem);
var calculate = function() {
if(jQuery("#frprice").length > 0) {
size = (jQuery("#foldet").val()).split(":");
fold = (jQuery("#fold").val()).split(":");
back = (jQuery("#black").val()).split(":");
front = (jQuery("#front").val()).split(":");
qlnt = jQuery("#qlnt").val();
qlt = jQuery("#qlt").val();
var str = parseInt(size[0])+parseInt(fold[0])+parseInt(back[0])+parseInt(front[0])+parseInt(qlnt)+parseInt(qlt);
tprice = parseInt(str);
jQuery("h3#price span").text(tprice);
}
};
var jd_timer;
var upload_on_progress = 0;
jd_error = function(errCode) {
clearTimeout(jd_timer);
if(errCode == 0) {
jd_show_msg("Please fill all required fields (*)");
}
if(errCode == 1) {
jd_show_msg("Invalid Email Address.");
}
if(errCode == 2) {
//jd_show_msg("Invalid Email Address.");
alert("Form sending failed. Please try again later");
}
if(errCode == 3) {
alert("Invalid Action. Please Contact Administrator.");
}
};
invalid_captcha = function(x) {
if(x == 0) {
alert("Please Enter Verification Code.");
} else {
alert("Invalid Verification Code. Try Again.");
jQuery(".jd_captcha_img").each(function() {
jQuery(this).attr('src', jQuery(this).attr('src')+'&x='+Math.random());
});
}
jQuery(".jd_captcha").val("");
};
jd_success = function() {
setTimeout(function() { window.location = document.URL+"?thank-you"; },2000);
};
upload_error = function(err,uid) {
upload_on_progress--;
jQuery("input[name=jd_upload_file_"+uid+"]").val("");
alert(err);
};
insertUpload = function(data,file) {
upload_on_progress--;
var tmpData = data.split(':');
if(tmpData.length == 3) {
var tmpCounter = 0;
jQuery("input[name=jd_upload_file_"+tmpData[2]+"]").val(file);
var updateInput = jQuery("#jd_upload_uri_"+tmpData[2]);
var updateData = tmpData[0] + ":" + tmpData[1];
updateInput.val(updateData);
} else {
alert("Uploading File Error. Please Try Again Later");
}
};
jd_show_msg = function(err) {
var myBox = jQuery("#jd_msg_box");
myBox.children(".text").text(err);
timer = setTimeout(function() { myBox.hide(); },3000);
myBox.show();
};
jQuery("select").change(calculate);
jQuery("#price").click(function(){
jQuery(this).hide();
});
jQuery(".jd_upload:eq(0), .jd_upload_filename:eq(0)").css("opacity",1);
jQuery(".file_input_hidden:eq(0)").show();
var jdModal = jQuery('#jdModal').html();
jQuery('#jdModal').remove();
var uploaderBox = jQuery(".uploader-box");
jQuery(".inp-file").click(function(e) {
if(upload_on_progress > 0) {
e.preventDefault();
alert("Prevented");
}
});
var cboxTopCache = 0;
var cboxLeftCache = 0;
var fixFileWin = function() {
var fixLeft = 585;
var cboxOffset = jQuery("#colorbox").offset();
cboxLeftCache = cboxOffset.left;
cboxTopCache = jQuery("#jd_upfile_1").offset().top;
jQuery(".uploader-box-1").css("top", (jQuery("#jd_upfile_1").offset().top) + "px");
jQuery(".uploader-box-2").css("top",(jQuery("#jd_upfile_2").offset().top) + "px");
jQuery(".uploader-box-3").css("top",(jQuery("#jd_upfile_3").offset().top) + "px");
uploaderBox.css("left",(cboxLeftCache+fixLeft) + "px");
};
jQuery(window).resize(function() {
var cboxOffset = jQuery("#colorbox").offset().left;
var cboxOffset2 = jQuery("#jd_upfile_1").offset().top;
if(cboxOffset != cboxLeftCache || cboxOffset2 != cboxTopCache) {
fixFileWin();
}
});
var formOnClick = function(e) {
e.preventDefault();
isCustomQuote = (jQuery(this).attr('id') == 'frprice')?false:true;
jQuery.colorbox({html:jdModal,opacity:0.8,overlayClose:false,transition:'none', onComplete: function() {
fixFileWin();
uploaderBox.show();
jQuery(".inp-file").change(function() {
var _this = jQuery(this);
if(_this.val() != "") {
if(upload_on_progress > 0) {
alert("Upload is still in progress. Please wait.");
} else {
jQuery("input[name=jd_"+_this.attr("id")+"]").val("Uploading File.. Please Wait..");
_this.parent().submit();
upload_on_progress++;
}
}
});
if(!isCustomQuote) {
jQuery("#product_form input[name=size]").val(size[1]);
jQuery("#product_form input[name=fold]").val(fold[1]);
jQuery("#product_form input[name=back]").val(back[1]);
jQuery("#product_form input[name=front]").val(front[1]);
jQuery("#product_form input[name=qlnt]").val(qlnt);
jQuery("#product_form input[name=qlt]").val(qlt);
jQuery("#product_form input[name=tprice]").val(tprice);
}
jQuery("#colorbox #product_form").submit(function(e) {
var tmp_progress = upload_on_progress;
if(tmp_progress > 0) {
e.preventDefault();
alert("Upload in progress. Please wait.");
}
});
}, onClosed: function() {
uploaderBox.hide();
}});
};
jQuery("#frprice").submit(formOnClick);
jQuery("#customs").click(formOnClick);
if(!isCustomQuote) {
calculate();
}
}
});
</script>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar('right'); ?>
<?php get_footer(); ?>
replace
jQuery("#file-upload-elem").remove();
With
jQuery("#file-upload-elem").hide();
jQuery.remove(), completely removes the selected element from the DOM
EDIT:
To show the element when you need it use
jQuery.show()
i.e jQuery("#file-upload-elem").show();
http://jsfiddle.net/MJwFj/2/
although it looks very rough when .remove() has been commented out the form loads
uploaderBox.hide();
The code above will hide the following, the above code is safe to remove if you don't want this to happen:
<form id="upload_form_1" class="uploader-box uploader-box-1" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data"><input type="file" name="upload_file_1" class="inp-file" id="upload_file_1" /></form>
<form id="upload_form_2" class="uploader-box uploader-box-2" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data"><input type="file" name="upload_file_2" class="inp-file" id="upload_file_2" /></form>
<form id="upload_form_3" class="uploader-box uploader-box-3" action="<?php echo site_url(); ?>/wp-content/themes/ecs/formHandler.php" target="formFrame" method="post" enctype="multipart/form-data"><input type="file" name="upload_file_3" class="inp-file" id="upload_file_3" /></form>
It's not clear exactly which element is being hidden but there is also a timer that triggers after 3 seconds to hide another element. Try removing the following also:
timer = setTimeout(function() { myBox.hide(); },3000);
The first, you may set the css role display to the element you wanted to as none
.form{
display:none;
}
then you just need to show the form with jQuery .show() function on event you wanted to, such button clicked or something else. For example :
$(document).ready(function(){
$('.classOfButton').on('click',function(){
$('.form').show();
);
})
Update
if you wanted to show the form within the page are loaded, you need to put the javascript in the end of page, or if you use jQuery you just need to use .ready() function and inside of it you show up the form with some delay if necessary.
$(document).ready(function(){
$('.form').show();
})