php - Submitting a bootstrap form not working -
i'm trying submit bootstrap form using php data entered form emailed me page. somewhere not working though, , unfortunately php knowledge lacking (and web searches have far brought nothing of use).
when click submit modal form in instantly closes (a default html thing?). re-opening modal displays the form error messages if have left forms blank. if submit form content present, nothing happens.
so question this: have done wrong, , how fix email send? also, can stop modal closing when content submitted not complete?
edit: have implemented "correct" php uploading image, gives me invalid file type when valid. echo $target_file returns file_dir suggesting failing ge name of file. have done wrong?
here php:
<?php if (isset($_post["submit"])) { $name = $_post['name']; $location = $_post['location']; $desc = $_post['desc']; //image upload $target_dir = "/img/gallery/"; $target_file = $target_dir . basename($_files["file"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) { $check = getimagesize($_files["file"]["tmp_name"]); if($check !== false) { echo "file image - " . $check["mime"] . "."; $uploadok = 1; } else { echo "file not image."; $uploadok = 0; } } // check if file exists if (file_exists($target_file)) { echo "sorry, file exists. please rename image."; $uploadok = 0; } // check file size if ($_files["file"]["size"] > 500000) { echo "sorry, file large. google how reduce image size or contact if need this."; $uploadok = 0; } // allow file formats if($imagefiletype != "jpg" && $imagefiletype != "png" && $imagefiletype != "jpeg" && $imagefiletype != "gif" ) { echo "sorry, jpg, jpeg, png & gif files allowed."; $uploadok = 0; } // check if $uploadok set 0 error if ($uploadok == 0) { echo "sorry, file not uploaded."; // if ok, try upload file } else { if (move_uploaded_file($_files["file"]["tmp_name"], $target_file)) { echo "the file ". basename( $_files["filetoupload"]["name"]). " has been uploaded."; } else { echo "sorry, there error uploading file."; } } $from = 'gallery upload form'; $to = 'email@example.com'; //i've changed stackoverflow $subject = 'new gallery image'; $body = "name: $name\n location: $location\n description: $desc\n \n $file"; if (!$_post['name']) { $errname = 'please enter name'; } if (!$_post['location']) { $errlocation = 'please enter image taken'; } if (!$_post['desc']) { $errdesc = 'please enter description of image'; } if (!$_post['file']) { $errfile = 'please upload image file'; } // if there no errors, send email if (!$errname && !$errname && !$errlocation && !$errdesc && $errfile) { if (mail ($to, $subject, $body, $from)) { $result='<div class="alert alert-success">thank you! image has been submitted.</div>'; } else { $result='<div class="alert alert-danger">sorry there error sending message. please try again later or report us.</div>'; } } } ?> and here html:
<div class="box"> <h2>upload picture</h2> <p>upload picture , we'll upload gallery. best picture each month featured page background. can upload pictures our facebook page <font color="darkcyan">#gallery</font>.</p> <br> <!-- model content --> <!-- button trigger modal --> <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#mymodalnorm">upload picture</button> <!-- modal --> <div class="modal fade" id="mymodalnorm" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <!-- modal header --> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"> <span aria-hidden="true">×</span> <span class="sr-only">close</span> </button> <h3 class="modal-title" id="mymodallabel">upload image</h3> </div> <!-- modal body --> <div class="modal-body"> <form role="form" method="post" action="index.php"> <div class="form-group"> <label for="name">your name</label> <input class="form-control" placeholder="john smith" type="text" name="name" required value="<?php echo htmlspecialchars($_post['name']); ?>"> <?php echo "<p class='text-danger'>$errname</p>";?> </div> <div class="form-group"> <label for="location">location</label> <input class="form-control" placeholder="south-west bank of trout pool." type="text" name="location" value="<?php echo htmlspecialchars($_post['location']); ?>"> <?php echo "<p class='text-danger'>$errlocation</p>";?> </div> <div class="form-group"> <label for="desc">picture description</label> <textarea class="form-control" name="desc" rows="3" placeholder="a picture of 6lbs trout, biggest season."><?php echo htmlspecialchars($_post['desc']); ?></textarea> <?php echo "<p class='text-danger'>$errdesc</p>";?> </div> <div class="form-group"> <label for="btn-upload">upload image file</label> <input type="file" id="exampleinputfile" name="file" value="<?php echo htmlspecialchars($_post['file']); ?>"> <?php echo "<p class='text-danger'>$errfile</p>";?> </div> <input id="submit" name="submit" type="submit" value="upload" class="btn btn-primary"> </form> </div> <!-- modal footer --> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> </div> </div> </div> </div> <?php echo $result; ?> </div> edit: stupid question - have configure server-side email sent?
your uploading file html form must have enctype="multipart/form-data" attribute.use $_files variable access information regarding uploaded file.
check these link more information on $_files
http://php.net/manual/en/reserved.variables.files.php
http://www.tutorialsscripts.com/php-tutorials/php-files-variable.php
Comments
Post a Comment