here is an upload button, from which user can choose the file
Basically what I want to do is whenever user chooses an image from that,
it should display it at the place where that "trees" image is.
I'm stuck, really need some help.
here is the code
<div class="user-editable-div">
<div class="image-div" id="image_div"><img src="images/image.jpg" id="bg_image" /></div>
<span class="upload-btn">UPLOAD IMAGE</span>
<input type="file" id="uploader" />
<div class="content-div">
<h1 contenteditable="true">USER EDITABLE</h1>
<p contenteditable="true">All elements on this page are user editable. You can edit them by simply clicking or by clicking on the edit button next to the element.</p>
</div>
</div>
when the user chooses a file from "#uploader" it should display the image in "#bg_image"
With this code when you try to upload image with use file controller at that time that image preview in bg_image element
<div class="user-editable-div">
<div class="image-div" id="image_div"><img src="images/image.jpg" id="bg_image" /></div>
<span class="upload-btn">UPLOAD IMAGE</span>
<input type="file" id="uploader" onchange="readURL(this,this.id);"/>
<div class="content-div">
<h1 contenteditable="true">USER EDITABLE</h1>
<p contenteditable="true">
All elements on this page are user editable. You can edit them by simply clicking or by clicking on the edit button next to the element.
</p>
</div>
</div>
<script>
function readURL(input,ids)
{
if (input.files && input.files[0])
{
var reader = new FileReader();
reader.onload = function (e)
{
$('#bg_image').attr('src', e.target.result).width(650).height(375);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
Try attaching change event to input type="file" element , using URL.createObjectURL() with argument this.files[0] within change handler to set src of img with .attr(attribute, value)
$(":file").change(function(e) {
$("#bg_image").attr("src", URL.createObjectURL(this.files[0]))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="user-editable-div">
<div class="image-div" id="image_div"><img id="bg_image"src="" /></div>
<span class="upload-btn">UPLOAD IMAGE</span>
<input type="file" id="uploader" accept="image/*" />
<div class="content-div">
<h1 contenteditable="true">USER EDITABLE</h1>
<p contenteditable="true">All elements on this page are user editable. You can edit them by simply clicking or by clicking on the edit button next to the element.</p>
</div>
</div>
Related
I am trying to make HTML template working with PHP.
Its located here
Since its HTML, I want load questions from My Database and So I have done coding like below
<?php
$i=0;
while($row=mysqli_fetch_array($result))
{ ?>
<div class="covid-test-wrap test-step">
<div class="test-progress">
<div class="test-progress-step">
<span class="step-number"><?php echo ($i+1)."/".$rowcount;?></span>
<svg>
<circle class="step-<?php echo $i+1;?>" cx="30" cy="30" r="28" stroke-width="4" fill="none" role="slider" aria-orientation="vertical" aria-valuemin="0" aria-valuemax="100" aria-valuenow="50"></circle>
</svg>
</div>
</div>
<h3><?php echo $row['question'];?></h3>
<div class="step-block">
<div class="form-group">
<input type="radio" name="package-plan" class="form-control" id="yes">
<label for="yes">Yes</label>
</div>
<div class="form-group">
<input type="radio" name="package-plan" class="form-control" id="no">
<label for="no">No</label>
</div>
Next
</div>
</div>
<?php
$i++;
}
?>
JavaScript for Next Button is like this
$(document).ready(function() {
'use strict';
$('.test-step .button').on('click', function(e) {
e.preventDefault();
$(this).parents('.test-step').next().addClass('active');
$(this).parents('.test-step').removeClass('active');
})
$('.test-step .prev-btn').on('click', function(e) {
e.preventDefault();
$(this).parents('.test-step').prev().addClass('active');
$(this).parents('.test-step').removeClass('active');
})
})
Using above code, My All questions getting loaded completed and showing fine on press Next button but input radio working for only first question and in next questions I am not able to click any choice, its looking like disabled. I am not getting idea why its acting like this. Let me know if anyone here can help me for same.
Thanks!
I need to handle if user upload the image from input type=file then pass the path otherwise pass img src path.
How?
<div class="thumb thumb-rounded thumb-slide">
<img src="<?php echo $result['staff_signature'];?>" alt="Signature IS BLANK">
<div class="caption">
<input type="file" class="file-input" data-show-caption="false" data- show-upload="false" accept="image/*" id="signature" name="signature">
</div>
</div>
You can upload user files to the server with AJAX from a form with field, but if you want to be nice to the user and show a preview, you HAVE to do the round trip and upload the file to the server first
As far i understand from ur question i think u need this..
<div class="thumb thumb-rounded thumb-slide">
<img src="<?php echo $result['staff_signature'];?>" alt="Signature IS BLANK">
<div class="caption">
<input type="file" class="file-input" data-show-caption="false" data- show-upload="false" accept="image/*" id="signature" name="signature">
</div>
</div>
<input type="hidden" name="imgsrc" id="imgsrc" value="<?php echo $result['staff_signature'];?>">
upload section
if($_FILES[signature]['name']!="")
{
//file upload code
}
else
{
$imgsrc=$_POST['imgsrc'];
//get the imgsrc value using GET/POST ..whatever u are using the form
}
Let me know your feedback
I want to show the user a image before the user uploads it to the server to make sure that this image is what the user wanted to upload.
I have tryed to do this with $_FILES['name']['tmp_name'] and put this in a tag but nothing happens.
<form action='' method='POST' enctype="multipart/form-data">
<header class='pageHeading'>Kop afbeedling toevoegen</header>
<section class='body'>
<div class='inputFrame'>
<img src="<?php if(isset($_FILES['image']['tmp_name'])){echo $_FILES['image']['name'];}?>"/>
<div class='input'>
<div class="cellFrame">
<div class="inputHeading">Afbeelding uploaden</div>
<div class="frame">
<div class="frameAlign">
<div class="displayFlie">
<input type='file' name='image'/>
</div>
<button name='upload' class='btnUpload btn'>Upload</button>
<div class="clr"></div>
</div>
</div>
</div>
</div>
<div class="clr"></div>
</div>
</form>
simple solution - grab your image data convert to base64 and output in your current view, so you don't need to copy the current tmp image into an public loction- like
$imageData = file_get_contents($_FILES['image']['tmp_name']); // path to file like /var/tmp/...
// display in view
echo sprintf('<img src="data:image/png;base64,%s" />', base64_encode($imageData));
After the image is submitted, it's already uploaded to the server in a temporary file. If you need to show the contents of the image from that temporary file, then you need to do a script that reads that file and outputs it with the right headers. Here's an example:
header('Content-Type: image/x-png');
readfile($_FILES['name']['tmp_name']);
exit();
any files uploaded to the server if not moved will be deleted automatically.
but do not worry. before uploading, you can display it using javascript or jQuery.
<form>
<input type="file" accept="image/*" name="" onchange="previewImage()">
<img id="preview">
</form>
<script>
function previewImage(){
var previewBox = document.getElementById("preview");
previewBox.src = URL.createObjectURL(event.target.files[0]);
}
</script>
Have you tried reading the file directly from the /tmp folder? Of course this can only happen after the upload, not before. So you have to do this before moving the file to its destinated folder, but right after the upload.
readfile($_FILES["name"]["tmp_name"]);
You have two ways of doing this.
The first is using a javascript code to show the preview before uploading to server, you can check this answer: Image Upload with Preview and Delete
The second one is to upload the image and retrieve a thumbnail from server to show in clientside, you can check this post: http://www.sitepoint.com/image-upload-example/
Yes, it is possible to show the image in the tmp folder. Add an onchange event for input type = file; which triggers a function and it loads the image.
!!! Don't forget to set width for img tag
function preview() {
$('#frame').attr('src',URL.createObjectURL(event.target.files[0]));
}
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<form>
<input type="file" onchange="preview()">
<img src="" width="100px" height="100px" id="frame">
</form>
</body>
I have a PHP form that is split into 3 separate PHP pages. The first page submits the form info which is then processed by a third party API. The returned (validated) results are then presented in the second PHP page along with a form for further processing.
My question is whether or not there is a way I can integrate this process into the BootStrap Wizard Plugin with its tab structure.
e.g. Fill and submit form by clicking on 'next' and have the Wizard plugin move to tab 2. showing the the next PHP page which has been processed.
<!-- Wizard -->
<section class="wizard">
<!-- Wizard navigation -->
<ul>
<li>Registration</li>
<li>Next step</li>
<li>Confirmation</li>
</ul>
<!-- Wizard progress bar -->
<div class="progress progress-line progress-striped">
<div class="progress-bar progress-bar-success"></div>
</div>
<!-- Wizard content -->
<div class="tab-content">
<div class="tab-pane" id="step1">
<h3>This is first step</h3>
<form method="post" action="myform.php?api=form&step=1">
<input type="text" name="phonenumber" id="phonenumber" />
<input type="submit" value="continue" class="btn btn-primary" />
</form>
</div>
<div class="tab-pane" id="step2">
<h3>Second step content</h3>
<form method="post" action="myform.php?api=form&step=2">
<input type="text" name="faxnumber" id="faxnumber" />
<input type="submit" value="continue" class="btn btn-primary" />
</div>
<div class="tab-pane" id="step3">
<h3>This is third final step (completed)</h3>
<p>Form Process Complete</p>
</div>
<!-- Wizard pager -->
<ul class="wizard pager">
<li class="previous">Previous</li>
<li class="next">Next</li>
<li class="next finish">Finish</li>
</ul>
</div>
</section>
<!-- /Wizard -->
<script src="/js/jquery.bootstrap.wizard.js"></script>
<script>
$(document).ready(function() {
$('.wizard').bootstrapWizard({onTabShow: function(tab, navigation, index) {
var wizard = $('.wizard');
var $total = navigation.find('li').length;
var $current = index+1;
var $percent = ($current/$total) * 100;
wizard.find('.progress-bar').css({width:$percent+'%'});
// If it's the last tab then hide the next button and show the finish instead
if($current >= $total && $total != 0) {
wizard.find('.pager .next').hide();
wizard.find('.pager .finish').show().removeClass('disabled');
} else {
wizard.find('.pager .next').show();
wizard.find('.pager .finish').hide();
}
}});
});
</script>
So what I'm trying to achieve is for the first form to show it's results in the second tab of the wizard.
Yes you can, I would suggest using the bwizard.js and bwizard.css plugin. And add a button to a form, now u going to have to call the action using ajax and not using an actual input of type submit. Using jQuery, on success of "btn_submit" you will taget the 2nd tab to focus to by giving each tab an I'd, or u can use page inspector and target the default I'd of each tab, which if I remember correctly used to be #step1 etc.
I am using the Flexible Map plugin on a wordpress site. The plugin has a form that allows the user to enter their 'from address' to get directions to the location displayed on the map. The form does not have an ID or class (and I am not able to add one).
I would like the user to be able to print the directions once the form is submitted, but I don't want the print button to show up until after the directions have displayed from the user pressing the submit button.
The directions are displayed in a table, so I was thinking I could use JQuery to say that when the table is displayed, then show the print div.
I'm thinking it's something like this, but I'm not sure how to format it based on a table (because the form does not have an ID):
jQuery(document).ready(function($) {
$('#idOfYourForm').on("submit", function () {
$('#print').show();
});
});
Any suggestions are appreciated!
EDIT Here is the code that is generated once the directions submit button is pressed:
<div id="my-dir-div" style="float: left; direction: ltr;">
<form>
<p>
<input type="text" name="from">
<input type="submit" value="Get Directions">
</p>
</form>
<div jstcache="0">
<div class="adp-warnbox" jsdisplay="warnings.length" jstcache="1" style="display: none;">
<div class="warnbox-c2" jstcache="0"></div>
<div class="warnbox-c1" jstcache="0"></div>
<div class="warnbox-content" jscontent="$this" jsselect="warnings" jstcache="5"></div>
<div class="warnbox-c1" jstcache="0"></div>
<div class="warnbox-c2" jstcache="0"></div>
</div>
<div jseval="setupPanelStep(this, $waypointIndex)" jsvalues="$waypointIndex:0;" jsselect="legs[0].start_address" jstcache="2">
<table id="adp-placemark" class="adp-placemark" jstcache="0">
<tbody jstcache="0">
<tr jstcache="0">
<td jstcache="0">
<img jsvalues=".src:markerIconPaths[$waypointIndex]" jstcache="14" src="http://maps.gstatic.com/mapfiles/markers2/icon_greenA.png">
</td>
<td class="adp-text" jscontent="$this" jstcache="12">211 South Elson Street, Kirksville, MO 63501, USA</td>
</tr>
</tbody>
</table>
</div>
<div jsvalues="$legIndex:$index;" jsselect="legs" jstcache="3" jsinstance="*0">
<div class="adp-legal" jscontent="copyrights" jstcache="4">Map data ©2013 Google</div>
</div>
</div>
<div id="print">
<input id="print" class="printbtn" type="button" value="Print Directions" onclick="return pop_print()">
<script type="text/javascript">
function pop_print(){
w=window.open(null, 'Print_Page', 'scrollbars=yes');
w.document.write(jQuery('div#my-dir-div').html());
w.document.close();
w.print();
}
</script>
</div>
I think you can try this (only if the table with id adp-placemark is available on the page then show it)
$(function(){
if($('#my-dir-div table#adp-placemark').length) $('#print').show();
});
Or, this one
$(function(){
if($('#my-dir-div table#adp-placemark td.adp-text').length) $('#print').show();
});