Jump to content

maxxd

Gurus
  • Posts

    1,661
  • Joined

  • Last visited

  • Days Won

    52

Posts posted by maxxd

  1. So, wait - do you want to style the page, or add controls to the page?

     

    If you're looking to style what's there, check the page source and make sure that your style sheet is being included. It could just be a targeting issue within the .css. Also, try printing the value of $hook to screen - looking at it, I'm not sure that WP is going to deliver "hotels.php", but rather something along the lines of "admin.php?page=hotels".

     

    If you want to add controls, start reading here - https://codex.wordpress.org/Settings_API and here - https://codex.wordpress.org/Creating_Options_Pages.

  2. Right. As I said, target was just a thing - assign the value of that to a variable you can use.

     

    If you're passing in a string reference to the DOM object (for instance:

    swapContent('http://myURL.com', array('testing','more'), 'myDivID');
    

    ), this should work for you:

    var tgt = '#' + target;
    
    $(tgt).html('<p>Woot</p>');
    

    If you're passing in the DOM object itself (as such:

    swapContent('http://myURL.com', array('testing','more'), $('#myDivID'));

    ), just use it directly:

    tgt.html('<p>Woot!</p>');
    
    • Like 1
  3. Is $ds defined in the function (or function sheet) you're altering? Check the code on the page you're using as an example - it's probably (I'm assuming you're using WordPress) a global, and you should be able to use it by adding

    global $ds;
    

    at the top of the function. However, it's difficult to tell without looking at the code.

  4. Thanks guys (or gals, not sure).

     

    The thing is, I've seen this method work for a dynamically created .zip file before, and can't quite figure out why it's not doing anything for a CSV. I'll give a shot to the redirect method, which hopefully will work in WP. And thanks much for the heads-up on the output stream. I'm not terribly excited about the prospects of writing and deleting a file on the server every time my client wants to export the data, so that'll put my mind at ease a bit!

  5. Try setting the $keys array index to the post ID? I'm honestly not entirely sure what you're hoping to see as the output. Right now, the $keys array is going to be a numerically-indexed array of page slugs, so the select options are probably going to look a lot like this:

    <select value='1'>page_slug_1</select>
    <select value='2'>page_slug_47</select>
    <select value='3'>page_slug_15</select>
    

    etc..

     

    If you want to associate the page with it's slug, create the array like this:

    foreach($pages as $page){
    	$keys[$page->ID] = $page->post_title;
    }
    

    then use $keys as the value of 'options'. I'm not familiar with the Quemalabs theme, so I don't know exactly how you're creating the select box, but from what you've said I think this'll work for you.

  6. Hey y'all. I've dug around on SO and other sites, and pretty much everything I'm finding is making me think that what I'm doing here should be working. Problem being, it's not. First, a little background.

     

    I'm trying to create a CSV export of a WordPress back-end report that I've built and have had working for a bit now. I'm using AJAX to gather the data for both the display and the export. So, the user selects a date range, clicks 'Go', and the system uses AJAX to populate the report data into the table as expected. At this point, the user can click the 'Export' button, and - theoretically - once again the page uses AJAX to gather the data and display a 'Save as...' window with the newly generated report.

     

    My PHP code:

    public function exportReportData(){
    	$data = $this->gatherReportData(false);
    	$tmp = tempnam(sys_get_temp_dir(), 'your_csv_dl');
    	if($tmp === false || !file_exists($tmp)){
    		print(json_encode(array('success',false)));
    		exit;
    	}
    	$fileName = 'report_'.(new \DateTime())->format('Ydmhis').'.csv';
    	$handle = fopen($tmp,'w');
    	foreach($data as $row){
    		fputcsv($handle,$row);
    	}
    	fclose($handle);
    	header('Content-Description: File Transfer');
    	header('Content-Type: text/csv');
    	header('Content-Disposition: attachment; filename='.$fileName);
    	header('Expires: 0');
    	header('Cache-Control: no-cache must-revalidate');
    	header('Pragma: public');
    	header('Content-Length: '.filesize($tmp));
    	readfile($tmp);
    	unlink($tmp);
    	exit;
    }
    
    

    The system outputs the expected data - I can view it in my console. However, it doesn't pop up the expected 'Save as...' dialog, and I have no idea why. I've tried Content-Type: application/octet-stream, text/csv, application/csv, and a couple others that I can't remember right now.

     

    So, a couple questions - first off, the obvious. Does anyone see anything in the code above that's causing it to not work as expected? Did I leave something out, use the wrong value for a header, name something incorrectly, anything at all? Secondly, if I'm creating the file in the server temp directory, is it necessary to unlink() it at the end of the script, or will garbage collection take care of it on it's own?

     

    Any and all help is much appreciated, and thanks for taking the time to take a look.

  7. If you're looking for CSS compatibility information, check CanIUse.com.

     

    As far as Safari support goes, modern versions on the Mac handle vh and vw just fine. If someone's using it in a Windows environment, well... support was dropped for that quite some time ago.

  8. It's possible the error is referring to the attempt to read $_REQUEST['sort'] - try

    print("<pre>".print_r($_REQUEST, true)."</pre>");
    

    before line 15.

     

    Also - and this is more a personal preference, so take it with a grain of salt and all, but don't use $_REQUEST. Variables in the $_REQUEST superglobal can come from $_GET, $_POST, $_SESSION, or $_COOKIE. Know what data you're looking for and where to find it. If you submit your form using post, check $_POST; if you submit using get, check $_GET.

  9. The $('#target').innerHTML was kind of a stub. I should've mentioned the code wasn't tested - sorry. My point was to get you moving in the right direction, not give you a cut and paste solution. It looks like you're passing target as a DOM reference, so the way you've got it set up now should be working. What's the output of the processing script in the console?

  10. You shouldn't have to append the data directly to the url - using the 'get' method will handle that for you, as well as JSON encoding the data. However, you do have to give the data to the ajax call.

    $.ajax({
    	type:'get',
    	url:href,
    	beforeSend:function(){
    		$('#target').html("<p>Doing something - please wait.</p>");
    	},
    	data:url_data,
    }).done(function(ajaxObject){
    	var resp = JSON.parse(ajaxObject);
    	if(resp.success == true){
    		$('#target').html("<p>Woot!</p>");
    	}else{
    		$('#target').html('<p>Processing error - system returned false!</p>');
    	}
    }).error(function(){
    	$('#target').html('<p>System error - not processing related!</p>');
    });
    

    Note that there' are both a done() and error() handler attached to this. sucess() will always fire as long as the call itself goes through - there's no guarantee that the processing was successful.

    • Like 1
  11. Try this in your CSS:

    #my-button{
    	position: absolute;
    	top: 50%;
    	-ms-transform: translateY(-50%);
    	-webkit-transform: translateY(-50%);
    	transform: translateY(-50%);
    }
    

    Obviously change the #my-button identifier to whatever ID you're using for the button, and make sure the surrounding container has a position: value of either 'absolute' or 'relative'.

  12. As long as you want unique usernames, the system is actually functioning as it should. While you're testing, either make up a new username for each manual test, or delete the inserted row after each manual test.

     

    And yes,

    header('location:login.php?msg=Registered_successfully');

    is what you want (note that I removed the space in the value of msg).

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.