Si te soy sincero, no veo cual es tu problema.
Por lo que he entendido tienes un formulario donde realizas una busqueda de ficheros y quieres que al darle al botón de Submit (el cual haría de tipo button, para ahorrarte el return false) te devuelva mediante AJAX los ficheros que cumplen las condiciones especificadas.
Con el código que tienes y reorganizando los ficheros ya lo tendrías.
Código HTML:
Ver original<form action="submits.php" method="post" id="form-searchfiles"> <label for="folderPath">Enter folder path containing the files
</label> <input name="folderPath" id="folderPath" type="text" placeholder="domains" required autofocus/><br/>
<label for="fileExtensions">Enter file extension(s) to scan
</label> <input name="fileExtensions" id="fileExtensions" type="text" placeholder="txt" required autofocus/><br/>
<input type="submit" name="searchfiles" id="searchfiles" value="Submit" />
submits.php:
Código PHP:
Ver original<?php
if(isset ($_POST['ajax'])) {
$folderPath = $_POST['folderPath'];
$fileExtensions = $_POST['fileExtensions'];
exit ('File does not exists'); }
require ('libraries/fileExplorer.class.php');
$fileExplorer = new fileExplorer;
$files = $fileExplorer->showFiles($folderPath, $fileExtensions);
?>
<div class="select">
<div class="title">Select the files you whant to process:</div>
<form method="post" id="form-selectfiles">
<input type="checkbox" onclick="toggleChecked(this.checked)"> Select / Deselect All<br/>
<div id="checkboxes">
<?php foreach ($files as $file):?>
<input type="checkbox" id="<?php echo $file; ?>" name="<?php echo $file; ?>"><?php echo $file; ?><br/>
<?php endforeach;?>
</div>
<input type="submit" name="selectfiles" id="selectfiles" value="Submit" />
</form>
</div>
<?php
}
?>
Código Javascript
:
Ver original$('#searchfiles').click(function() {
var folderPath = $('#folderPath').val();
var fileExtensions = $('#fileExtensions').val();
if (!folderPath) {
alert('You did not enter a foltder path');
return false;
}
if (!fileExtensions){
alert('You did not enter file extension(s');
return false;
}
var form_data = {
folderPath: $('#folderPath').val(),
fileExtensions: $('#fileExtensions').val(),
ajax: '1'
};
$.ajaxSetup({
cache: false ,
timeout: 5000
});
$.ajax({
url: "submits.php",
type: "POST",
data: form_data,
success: function(datos){
$('#form-searchfiles').fadeOut('slow');
$('.select').fadeIn('slow');
$('#resultado').html(datos);
},
error:function(x,e){
if(x.status==0){
alert('You are offline!!\n Please Check Your Network.');
}else if(x.status==404){
alert('Requested URL not found.');
}else if(x.status==500){
alert('Internel Server Error.');
}else if(e=='parsererror'){
alert('Error.\nParsing JSON Request failed.');
}else if(e=='timeout'){
alert('Request Time out.');
}else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
return false;
});
function toggleChecked(status) {
$("#checkboxes input").each( function() {
$(this).attr("checked",status);
});
};