Pergunta

I bought the uploadifive script and want to change some things. I've added a textfield called "name" and a textfield called "about".

The basic script that comes with Uploadifive is:

the form:

    <form action="<?php echo $domein.'/uploadstap2.php'; ?>" method="post" name="THEFORM">
    <input name="naam" type="text">
    <div id="queue"></div>
    <input id="file_upload" name="file_upload" type="file" multiple>
    <a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>
</form>

The script:

<script type="text/javascript">
    <?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadifive({
            'auto'             : false,
            'checkScript'      : 'check-exists.php',
            'queueID'          : 'queue',
            'uploadScript'     : 'uploadifive.php',
            'onUploadComplete' : function(file, data) { console.log(data); }
        });
    });
</script>

The creaters wrote the following on there webppage:

A JSON object containing additional data to send to the server-side upload script. Data sent via this option will be sent via the headers and can be accessed via the $_POST array (if using the ‘post’ method). So if you send something like {‘someKey’ : ‘someValue’}, then you can access it as $_POST['someKey'].

Dus, ik kan dit doen:

<script type="text/javascript">
    <?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadifive({
            'auto'             : false,
            'checkScript'      : 'check-exists.php',
            'formData'         : {'someKey' : 'someValue'},   !!!!!!! <<<< this is what i just added >>>>!!!!!
            'queueID'          : 'queue',
            'uploadScript'     : 'uploadifive.php',
            'onUploadComplete' : function(file, data) { console.log(data); }
        });
    });
</script>

But i need the value that people enter in "name" and "about" to be send on uploadComplete. How can i send this values in stead of: {'someKey' : 'someValue'}

Can somebody help me?

Foi útil?

Solução

You can try $('input[name=something]').val() (where something is the name of your input) to get the value of the textbox by checking the name of the element. You can use like this for your example

'formData' :{name:$('input[name=name]').val(),about:$('input[name=about]').val()}

Outras dicas

Your HTML Form:

   <form>
   <input type="input" id="firstname"> First name </input>
   <button>Submit</button>
   </form>

Inside your jquery wrapper (or javascript file) and this would pass the variable throughout.

   var someValue = $("#firstname").val();

   $.ajax({
       type: 'POST',
       url: './aProcessorScript.php',
       data: JSON.stringify ({'someKey' : 'someValue'}),
       success: function(data) { alert('data: ' + data); },
       dataType: 'json'
   });
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top