Estoy trabjando en una pequena aplicacion de interactuacion con ficheros de Cpanel y la db.
Tengo esto
Código HTML:
<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" /> </form> <br/> <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"> [B]<?php foreach ($files as $file):?> <input type="checkbox" id="<?php echo $file; ?>" name="<?php echo $file; ?>"><?php echo $file; ?><br/> <?php endforeach;?>[/B] </div> <input type="submit" name="selectfiles" id="selectfiles" value="Submit" /> </form> </div>
Código HTML:
$('#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 }); //var ajax_load = "<img src='resources/images/ajax-loader.gif' alt='loading...' />"; $.ajax({ url: "submits.php", type: "POST", data: form_data, success: function(html){ $('#form-searchfiles').fadeOut('slow'); $('.select').fadeIn('slow'); alert(html); //$('#content').html(ajax_load).append('<div id="result">' + html + '</div>').fadeIn(); }, 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); }); };
Lo que busco es simplemente al mandar el primer formulario, construir un segundo folmulario (el de class='select') con unos checkbox que tengan como valores los resultados del primer formulario.
Código PHP:
if(isset ($_POST['ajax']))
{
$folderPath = $_POST['folderPath'];
$fileExtensions = $_POST['fileExtensions'];
if(!file_exists('libraries/fileExplorer.class.php')){
exit ('File does not exists');
}
require ('libraries/fileExplorer.class.php');
$fileExplorer = new fileExplorer;
$files = $fileExplorer->showFiles($folderPath, $fileExtensions);
}