-1

i have this code in it how to send form value to php file .

 <form role="form" id="upload_form" method="post" enctype="multipart/form-data">

     <div class="form-group">
     <label for="formlabel">Title</label>
     <input class="form-control" name="title" id="title" placeholder="Enter Software Name" type="text" value="<?php if(isset($title)){echo $title;}?>" required>
     </div>

    <div class="form-group">
    <label>Short Meta Description atleast 155 words</label>
    <textarea class="form-control" name="shortdec" id="shortdec" rows="3" required><?php if(isset($shortdec)){echo $shortdec;}?></textarea>
</div>


    <div class="form-group">
    <label>File input</label>
    <input name="softpost" id="softpost" type="file" required>
</div>


     <input type="button" value="Upload File" onclick="uploadFile()">
      <progress id="progressBar" value="0" max="100" style="width:300px;"></progress>
      <h3 id="status"></h3>

in javascript file work file data fine but i want to send also title and shortdec id value also please tell me how to do it

var formdata = new FormData();
    formdata.append("softpost", file);
Dave
  • 3,073
  • 7
  • 20
  • 33
Saad Awan
  • 153
  • 2
  • 3
  • 14
  • 2
    Possible duplicate of [Sending multipart/formdata with jQuery.ajax](http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax) – Md. Khairul Hasan Oct 06 '16 at 07:49

2 Answers2

1

If I understand you right, you want to send "normal" stuff with files.

Well, it's super easy:

formdata = new Formdata();
formdata.append('softpost', file)
formdata.append('name', 'My super file')

That's it!

Matt

math2001
  • 4,167
  • 24
  • 35
1

You can do this with,

Jquery

$("form#upload_form").submit(function(){
    //Fetch Form Data i.e it will include all the form elements including file and other form inputs
    var formData = new FormData($(this)[0]);
    .........AJAX CALL...........
    return false;
});

JavaScript

var form = document.getElementById("upload_form");
var formData = new FormData(form);

Just use new FormData($(this)[0]); to get the form fields and proceed with the normal AJAX call.You can now fetch the title, file and description element on your backend php code.

Runcorn
  • 5,144
  • 5
  • 34
  • 52