1

i use this script to upload an image and send data with Ajax.

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

        $('#start_upload').on('click', function () {
            $('#file_upload').uploadifive('upload');
        });

    });
</script>

The form:

    <form id="upload_document">
    <input id="file_upload" name="file_upload" type="file" multiple>

    <input name="form_userid" id="form_userid" type="hidden" value="<?php echo $_SESSION['userId']; ?>" />                      

    <input type="button" id="start_upload" name="uploadenFormSend" value="Bestand(en) uploaden" class="button-pink">                        

                </form>  

When i send the form, $_POST['formInput'] returns:

form_userid=13647

But i only need the value (13647). What can i do to make this happend?

Rick A.
  • 213
  • 2
  • 4
  • 11
  • Possible duplicate of https://stackoverflow.com/questions/15173965/serializing-and-submitting-a-form-with-jquery-post-and-php – Lalit Jan 22 '18 at 11:09
  • Are you asking how to extract `13647` from `form_userid=13647` using PHP...? –  Jan 22 '18 at 11:10
  • 3
    change this `var formInput = $(":input,:hidden").serialize();` to this `var formInput = $(":input#form_userid").val();` – Kresimir Pendic Jan 22 '18 at 11:10
  • 1
    Also, why would you send SESSION data to the client like that, then send it back to the server? Doesn't make any sense. –  Jan 22 '18 at 11:12
  • 1
    Are you aware that your code is using es6 shorthand object syntax? Or was it a sad coincidence – Musa Jan 22 '18 at 12:28

0 Answers0