Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to create website to upload a file into a directory inside called "Uploads". I was wondering how to do this with HTML, JavaScript and/or PHP. I am new to website building. Thanks.
Try this:
<form id="form_request_file" method="post" action="index.php" enctype="multipart/form-data">
<table align="center" width="525" border="0">
<label for="uploaded" class="control-label col-sm-2">Upload File</label>
<input id="uploaded" name="uploaded" type="file"/>
<input value="Submit" name="submit" type="submit"/>
</form>
<?php
if (isset($_POST['submit'])) {
if (isset($_FILES['uploaded'])) {
$path = "uploaded_docs/";
$file_name = basename($_FILES['uploaded']['name']);
$target = $path . $file_name;
if (move_uploaded_file($_FILES["uploaded"]["tmp_name"], $target)) {
echo $file_name . " was uploaded";
} else {
echo "Could not upload";
}
}
}
?>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
So I'm new to coding such as Javascript and PHP, I need to create a form that will be hosted on a site which on a submit will send an email dependent on which checkbox is ticked, the different checkboxes will go to different emails, would I need to use a PHP post for this and is there any need for Jquery at all? or could I just use PHP? would love the help. Thank you
<?php
$mail1 = "test#test.com";
$mail2 = "test2#test.com";
$mail3 = "test3#test.com";
if(isset($_POST["MainCB"])) {
$mail1 = $_POST["MainCB"];
}
if(isset($_POST["ITCB"])) {
$mail2 = $_POST["ITCB"];
}
if(isset($_POST["CateCB"])) {
$mail3 = $_POST["CateCB"];
}
if(isset($_POST['submit'])){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$MainCB = $_POST['MainCB'];
$ITCB = $_POST['ITCB'];
$CateCB = $_POST['CateCB'];
$subject = "Form submission";
$message = $first_name . " " . $last_name . " " . $MainCB . " " . $ITCB . " " . $CateCB;
}
?>
<html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Maintenance:<input type="checkbox" id="MainCB"><br>
IT: <input type="checkbox" id="ITCB"><br>
Catering: <input type="checkbox" id="CateCB"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
You can create a form like this
<form action="mail.php" method="POST">
<input name="checkbox1" value="email1#yahoo.com" type="checkbox"></input>
<input name="checkbox2" value="email2#gmail.com" type="checkbox"></input>
<button type="submit">Test</button>
</form>
And in your mailing script you can retrieve the checkbox value.
if(isset($_POST["checkbox1"])) {
$mail1 = $_POST["checkbox1"];
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
[here is the code of my date input field, if i submit empty input date field but on view page date is 0000-00-00 instead of empty or nothing ]
<div class="col-sm-3 col-sm-offset-1">
<div class="input-group">
<input type="text" name="date_b" placeholder="mm/dd/yy" class="form-control datepicker" value="<?php
if (!empty($assessment_goal->date_b)) {
echo $assessment_goal->date_b;
}
?>" data-format="dd-mm-yyyy">
<div class="input-group-addon">
<i class="entypo-calendar"></i>
</div>
</div>
</div>
I wrote a Function for this the other Day:
function ctd($datetime, $format=false, $displayzero=false){
$timestamp = strtotime($datetime);
if(!$format){
$format = 'd.m.Y'; // <---------- your default Date-Format
}
if($timestamp > strtotime('0000-00-00 00:00:00')){
return date($format, $timestamp);
}else{
if($displayzero){
return str_replace(1, 0, date($format, strtotime('0001-01-01 00:00:00')));
}else{
return false;
}
}
}
With this Function it would be enough to write:
echo ctd($assessment_goal->date_b);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an image upload script using PHP with a simple multiple file select and then an upload function like below:
mysql_connect("localhost", "root", "") or die("error");
mysql_select_db("repo") or die("error");
$imgerror = '';
if(isset($_POST['log'])){
foreach($_FILES['files']['tmp_name'] as $key => $name_tmp){
$name = $_FILES['files']['name'][$key];
$tmpnm = $_FILES['files']['tmp_name'][$key];
$type = $_FILES['files']['type'][$key];
$size = $_FILES['files']['size'][$key];
$dir = "content/images/".$name;
$move = move_uploaded_file($tmpnm,$dir);
if($move){
$hsl = mysql_query("insert into files values('','$client','$name','$type','$size',now())");
if ($hsl){
$imgerror = "IMAGE(S) UPLOADED SUCCESSFULLY";
} else {
$imgerror = "CANNOT CONNECT TO DATABASE";
}
} else {
$imgerror = "NO IMAGES SELECTED";
}
}
}
HTML:
<div class="uploadContainer">
<div><i><?php echo $imgerror ?></i></div>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" name="log" value="Upload">
</form>
</div>
I did find some information using jQuery from another question here but have no idea how I would implement this into my code, or maybe someone could suggest an alternative. All I am trying to do is select the files, and make it automatically submit without pressing a submit button.
Any help would be appreciated,
Thanks
The onchange event works for inputs type file. Next code auto-submits "once files have been selected" (tested in Mozilla Firefox) :
<html>
<head>
<script type="text/javascript">
function on_change ()
{ alert( "File(s) chosen!" +
"\n\n" +
"Click to submit files to upload." );
document.getElementById( "frm" ).submit();
}
</script>
</head>
<body>
<form id="frm" action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple onchange="on_change()">
<input type="submit" name="log" value="Upload">
</form>
</body>
</html>
Of course, you will have to remove the JavaScript "alert" window, it's there to show that the "onchange" event works.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
The Code is:
<?php include 'connection.php';
if($logged_in=='yes')
{
echo "hell yea!"; //just for test and it works
?>
<script type="text/javascript">
alert("test 1 2 3"); //works too.
$("#form1").hide(); //to hide login form, but doesn't work
</script>
<?php
}
?>
I think question is quite clear. What is the reason? Thanks in advance.
EDIT: The session events are work fine by connection.php. No problem logging in or logout etc.
Here is my HTML code:
<div id="form1" name="form1" >
<label for="username"></label>
<input type="text" name="username" id="username" placeholder="Username" class="textbox"/>
<label for="password"></label>
<input type="password" name="password" id="password" placeholder="Password" class="textbox"/>
<span id="submit" class="submit">Log in</span>
</div>
<div>
<span id="logged_in" class="logged_in">Hello user etc.</span> //normally it is hidden from css.
</div>
and here is how I login:
$("#submit").click(function(){
$.ajax({
type:"POST",
url:"login.php",
data: '{"username":"'+$("#username").val()+'","password":"'+$("#password").val()+'"}',
dataType: "json",
success: function(data) {
if(data.ok=="done!"){
$("#form1").hide();
$("#giris").show();
$("#giris").html('Hello '+data.name+' '+data.lastname+' My Account');
}
else if(data.ok=="No such user!")
alert("No such user");
else
alert(data.ok); //activation required
}
});
});
EDIT: alert() line. HTML code added. Jquery part is added. And this forum tells me my post is mostly code so I think I have type something here. And I think I just did.
Try this code. Hope it will work.
<?php include 'connection.php';
if($logged_in=='yes')
{
echo "hell yea!"; //just for test and it works
?>
<script type="text/javascript">
$(document).ready(function(){$("#form1").hide(); });
</script>
<?php
}
?>
where dou you get tehe value of the session????
<?php
session_start();
// store session data
$_SESSION['logged_in']='yes';
?>
then
<?php include 'connection.php';
//////if($logged_in=='yes')
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']=='yes')
{
echo "hell yea!"; //just for test and it works
?>
<script type="text/javascript">
$("#form1").hide(); //to hide login form, but doesn't work
</script>
<?php
}
?>
check this link: http://www.w3schools.com/php/php_sessions.asp
I hope this help you men!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Using this open source file:
https://raw.github.com/openemr/openemr/master/interface/billing/sl_eob_search.php
I want to do auto submit form and is not responding.
I am using as reference this Auto populate form and auto submit with URL Parameters
which is what I would like to do - submit URL parameters but is not working.
REVISED
1st I added an id to the <form>, left the "values" on the textbox unchanged as I'm passing those values via URL.
<form method='post' action='sl_eob_search.php' id='search_invoice'
enctype='multipart/form-data'>
.
.
.
<td>
<input type='text' name='form_pid' size='10'
value='<?php echo $_POST['form_pid']; ?>'
title='<?php xl("Patient chart ID","e"); ?>'>
</td>
<td>
<?php xl('Encounter:','e'); ?>
</td>
<td>
<input type='text' name='form_encounter' size='10'
value='<?php echo $_POST['form_encounter']; ?>'
title='<?php xl("Encounter number","e"); ?>'>
</td>
.
.
.
<td>
<input type='submit' name='form_search' id='search'
value='<?php xl("Search","e"); ?>'>
</td>
.
.
.
</form>
SUBMIT BUTTON
I added an "id" attribute, and after the </form> closed:
<script type="text/javascript">
$(document).ready(function() {
$("#search").submit();
});
</script>
It didn't work... then went and got the form id:
document.forms['search_invoice'].submit();
And nothing happens.
You have used the id of the submit field (search):
<script type="text/javascript">
$(document).ready(function() {
$("#search").submit();
});
</script>
You should use the id of the form instead:
<script type="text/javascript">
$(document).ready(function() {
$("#search_invoice").submit();
});
</script>
Solved it by using click instead of submit!!
$(document).ready(function(){$("#search").click();});
Thanks!!