- <form id="uploadform" name="uploadform" enctype="multipart/form-data">
- <p class="short">Email Address <small>(required)</small></p>
- <input type="text" name="email" id="email" placeholder="eg: me@dennisaucoin.com" tabindex="1" class="short" /><br />
- <p class="short">Amount Due <small>(required)</small></p>
- <input type="text" name="amount" id="amount" placeholder="eg: $500.00" tabindex="2" class="short" /><br />
- <p class="short">Due In <small>(required)</small></p>
- <input type="radio" id="due30" name="duein" value="30" class="duein" />30 Days <input type="radio" id="due45" name="duein" value="45" class="duein" />45 Days <input type="radio" id="due60" name="duein" value="60" class="duein" />60 Days <input type="radio" id="duexx" name="duein" value="xx" class="duein" /><input type="text" name="duenum" id="duenum" value="" style="width:25px;" disabled="true" /> Days<br />
- <p class="short">File <small>(required)</small></p>
- <input type="file" name="file" id="file" tabindex="2" class="short" /><br />
- <p class="short">Status <small>(required)</small></p>
- <input type="radio" id="unpaid" name="status" value="unpaid" />Unpaid <input type="radio" id="paid" name="status" value="paid" />Paid<br />
- <p class="short">Notes <small>(hidden)</small></p>
- <textarea name="notes" id="notes" tabindex="4" class="short"></textarea><br />
- <input type="submit" value="Upload Invoice" id="submit" tabindex="7" class="short" /> <input type="reset" value="Reset" id="reset" tabindex="8" class="short" />
- </form>
I can get it to validate the form correctly, but I can not seem to get the file upload / checked passed to the PHP file once you click the link.
The JQUERY code is:
- $('#uploadform').submit(function() {
- var email = $('#uploadform input:eq(0)').val();
- var amount = $('#uploadform input:eq(1)').val();
- var duein = $('input[name=duein]:checked', '#uploadform').val();
- var duenum = $('#uploadform #duenum').val();
- var file = $('input:file').val();
- var extension = file.replace(/^.*\./, '');
- var status = $('input[name=status]:checked', '#uploadform').val();
- var dataString = 'email=' + email + '&amount=' + amount + '&duein=' + duein + '&duenum=' + duenum + '&file=' + file + '&status=' + status;
-
- if(!isValidEmailAddress( email ) || amount=='' || (duein=='' || (duein=='xx' && duenum=='')) || file=='' || status=='') {
- $('#alert span').html('Please fill in the required fields.<br /><strong>Please try again.</strong>');
- $('#alert').fadeIn().click(function() {
- $(this).fadeOut();
- });
- } else if($.inArray(extension, ['pdf']) == -1) {
- $('#alert span').html('Please make sure you are upload a <strong>PDF file</strong>.<br /><strong>Please try again.</strong>');
- $('#alert').fadeIn().click(function() {
- $(this).fadeOut();
- });
- } else {
- $.ajax({
- type: 'POST',
- url: 'http://www.dennisaucoin.com/admin/upload.php',
- data: dataString,
- success: function(x){
- $('#alert span').html(x);
- $('#alert').fadeIn().click(function() {
- $(this).fadeOut();
- $('#email').val("");
- $('#amount').val("");
- $('#file').val("");
- $('#duenum').val("");
- $("#duenum").attr("disabled", true);
- $("input:radio").removeAttr("checked");
- });
- }
- });
- }
- return false;
- });
And I am using the following for the PHP code:
- <?php
- include("somefile.php");
- $email = $_POST['email'];
- $amount = $_POST['amount'];
- $duein = $_POST['status'];
- $duenum = $_POST['duenum'];
- $status = $_POST['status'];
- $file = $_FILES['file'];
- $notes = $_POST['notes'];
- $temp = explode(".", $_FILES['file']);
- if($email == "" OR $amount == "" OR $duein == "" OR ($duein == "xx" AND $duenum == "") OR $status == "") {
- echo 'Please fill in the required fields. ('.$_GET['file'].')<br /><strong>Please try again.</strong>';
- } elseif($temp[1] != "pdf") {
- echo 'Please make sure you are upload a <strong>PDF file</strong>. ('.$_FILES[file].') <br /><strong>Please try again.</strong>';
- } else {
- $invoice = rand_string(15);
- if (!move_uploaded_file($file, "../pdfs/".$invoice.".pdf")) {
- echo 'There was an error while trying to upload your file.('.$_FILES[file].')<br /><strong>Please try again.</strong>';
- } else {
- $id = rand_string(15);
- if($duein == "xx") {
- $duedate = mktime(0, 0, 0, date("m"), date("d")+$duenum, date("Y"));;
- } else {
- $duedate = mktime(0, 0, 0, date("m"), date("d")+$duein, date("Y"));;
- }
- mysql_query("INSERT INTO `sometable` (`id`, `email`, `invoice`, `email`, `amount`, duein`, `status`, `notes`, `created`, `updated`) VALUES ('$id', '$type', '$invoice', '$email', '$amount', '$duedate', '$status', '$notes', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())");
- echo 'Your invoice has been upload to the website and the user has been notified via email.<br /><strong>You can either enter a new user or go back to the main page.</strong>';
- }
- }
- ?>
If anyone can help me out, it would be much appreciated. I am kinda in a pickle right now because I can make this part of my website live without this feature working.
Thank you,
Dennis
Thanks for all your help. If you every need anything PM me back.