Jump to content

maxxd

Gurus
  • Posts

    1,698
  • Joined

  • Last visited

  • Days Won

    53

Everything posted by maxxd

  1. Omitting the action attribute from a form tag is the current best practice, yes. As far as data/form security goes, it takes more than just that - it takes things like using a nonce and validating and sanitizing any user-submitted data before you do anything with it. Even then, you'll need to use prepared statements for any database interactions that involve said user-submitted data.
  2. Not gonna lie, I didn't realize Smarty was still in active development but looking at the github repo it clearly is, so if it's something you're invested in it doesn't seem like a lost cause. As I said, it's been a bit since I've explored it - I moved to Twig for a bit, then my jobs moved me to Laravel with Blade and/or Vue. All that aside, whatever template language you're using won't affect your routes. I'm sure others will kick in on this, but if you're just learning and starting fresh and you want to adhere to MVC patterns while keeping things DRY and using pretty URLs for routing, it might not be a bad idea to go straight to a framework just so you don't have to recreate the wheel. It's always good to understand the things a framework is doing at the base level, but honestly these days the most popular and most used frameworks take care of so much of the crap work that it's kinda worth learning backwards IMO. If you're working on updating an existing plain PHP code base then obviously ignore that opinion entirely; your situation is going to supersede any bullshit I may spout about the ease of adopting a framework. On the other hand, if you're planning on rewriting everything anyway, why not make it a bit easier on yourself? There are several frameworks out there, so if you decide to go that route do some research. Laravel is the most popular PHP framework and once you get used to its opinions it is pretty easy to deal with and offers some nice sugar out of the box, but there's a lot of magic there. In my experience CodeIgniter 4 is quite good, but offers less default functionality (and thereby less magic). I've heard good things about the latest version of Cake though I've never tried it. And from early experience with the latest major version and looking at the repo, Yii is ... not awesome. However, maybe that's changed?
  3. It sounds like you're looking for a pretty URL? If so, this is typically set up as a rewrite rule. I haven't looked at Smarty in a long time, and a quick Google search didn't return anything it specifically does to enable pretty URLs, so it's probable you'll have to update your .htaccess file (assuming you're using Apache - I'm not sure where or how this happens if you're using nginx or another server) with the rule to make it happen. If you're looking to go with more of a single page application style pattern, there are several to many other considerations to take into account.
  4. You're also ending the if statement in the middle of the loop - you can't do that. If the conditional applies to each row pulled from the database (it doesn't look like it does) then put the if statement inside the loop. Otherwise, end it after the loop. And as mac_gyver pointed out, you'll be better served going with PDO over mysqli.
  5. As kicken explained, ::before will come before the content inside the specified element, not before the specified element itself. ::after works the same way, only, you know - after the content of the specified element.
  6. Works for me - what exactly are you seeing? <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Testing before</title> <style> .color-top-border-pink-green:before { background: linear-gradient(to right,#e0218a 17.85%,#bff010 53.28%,#96BD0C 100%); content: ""; height: 4px; width: 100%; display: block; } .color-top-border-pink-green{ height: 350px; width: 99vw; background: url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2073&q=80') center center no-repeat; } </style> </head> <body> <div class="color-top-border-pink-green"></div> </body> </html> Note that there is a small chance I'm breaking copyright rules with that background image - I honestly don't know. It comes from here: https://unsplash.com/photos/KMn4VEeEPR8
  7. It really doesn't matter - I personally like OOP, even in plain PHP projects. However, when I start something new I reach for Laravel because my jobs have used Laravel for the past 4 or so years and by now I'm somewhat familiar with it. I also liked CodeIgniter 4, though there's not as much built-in functionality there as Laravel (but that can be nice as there's also not as much magic to deal with). Biggest problem I find I have nowadays jumping into a procedural or functions-based system is keeping track of what function comes from where. When everything is in the global namespace I find that things can get messy and confusing.
  8. What's the issue you're trying to solve? I'm extrapolating (perhaps quite heavily, tbh) but given your variable names I wonder if what you're trying to achieve would be better suited to CSS than JS.
  9. That's a completely different form in the JS Fiddle than what you've described already. Post the code and we can help. Some more things right off the top, don't set the form 'action' attribute based on what button's clicked - use the JS to set a hidden field in the form and leave the action attribute empty. That way the form will submit to the current URL. Set up your page in this order from top to bottom: PHP HTML JavaScript This allows you to handle the form submission first and display any errors to the user. It also allows you to not have to maintain three separate files for very similar functionality. Also - as I said before - prepare the query before the loop, then set $paramValue and execute the query in the loop. This way you're not wasting cycles preparing the same statement on every iteration - it only needs to be done once.
  10. You don't have a form input named 'users' and you never actually execute the query. That's a couple of several issues I see with this code - first, I assume your php is being called via ajax from the JS setUpdateAction() function? If so, you'll want to echo output and let your javascript handle the return instead of issuing a location header. Also, one of the joys about prepared statements is that you can prepare them once and use them multiple times - if you're doing the update in a loop prepare the statement before the loop, then bind and execute it in the loop. Also, if you're using mysqli I recommend switching to PDO now - it's just a better interface. Beyond that, you don't need two consecutive require_once statements for the same file; the name pretty much says it all (require once), and there's no need to jump through the hoops you're doing to assign evenRow or oddRow class names - just use CSS's nth-child() selectors.
  11. No matter what, by passing no third parameter to the filter_input function no filtering will actually happen and all of this is pointless. From the docs: filter_input( int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0 ): mixed and It's not clear what's happening with the submitted data (except for the one random output of $preApprovalAmount), but the OP needs to actually handle the input in a manner appropriate for the usage. If it's for a DB query, use prepared statements. If it's for output, use htmlspecialchars() or htmlentities().
  12. I could be remembering incorrectly, but I feel like this used to be available before google announced the move to GA4 and away from its Universal Analytics. In my experience, the move to GA4 made everything more complex, time consuming, and difficult. In my last job even extremely experienced data scientists were having trouble figuring out how to map and track user interactions, and this was after extensive meetings with the dev team about implementation. This is probably a jaded and unfair opinion, but I feel like as long as a company/user has enough money, google will find a away to show them the data they're looking for. Grumpy rant over...
  13. You'll need to use https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText to actually copy the text into the clipboard. You'd do this in the copyToClipboard() function kicken's post recommended you create.
  14. Continuing a long history of over-engineering because it reads easier to my particular brain: echo (new DateTime('first day of last month', new DateTimeZone('America/New_York')))->format('M j, Y'); Returns 'May 1, 2023' which, as of today, is correct. Thanks @Barand and @requinix.
  15. Well damn - I had in my head that it accounted for that. I was wrong.
  16. Or, if you just really like to over-engineer things: echo (new DateTime('now', new DateTimezone('America/New_York')))->sub(new DateInterval('P1M'))->format('M j, Y'); As dumb as it may sound given the length of this statement versus requinix and Barand's answers, this is easier for my brain to read.
  17. That's still not making a whole ton of sense. The original code you've posted is using fetch to call to a php script, which I assume is pulling data from a database. It's presenting that data as an array - there's really no getting around that. One way or another you'll need an iterable interface in order to loop through the dataset to present the data. An array is the most convenient way; you could json-encode the data before php outputs it so that it comes across as an object in javascript, but really the way it's being used here that's mostly semantic. It sounds like there's something else going on that we don't know; is there caching involved? Like Redis or Memcached? Explain what goal you're trying to achieve, not how you want to achieve it.
  18. You can also switch to PDO and get the benefits of not having go through extra steps like explicitly binding parameters (you can pass an array to PDOStatement::execute). Granted you'll still have to pass it an array that matches the parameters in the query, but it's less typing. There are also other reasons to move to PDO; the simplified interface and much easier readability, for example.
  19. Not gonna lie, I have no idea how they do it. In my experience though, even large corporate entities that are respected in the field like MC or CC the results are just kind of assumed to be legit. An agency I recently worked with was adamant about pointing out to clients that it couldn't guarantee specific numbers on email opens, reads, or deletions because the numbers were at best kinda reliable... I assume the big players have some sort of sway with major email providers, but I have no proof of that. Obviously tracking results of clicks from the email to the website are more reliable as you simply append the tracking parameters to the end site from the email to the URL in the email itself. Doesn't help with opens, though - sorry. I have to assume someone here is more knowledgeable than I on the subject.
  20. Your best bet here is to use an email service. SugarCRM, Constant Contact, MailChimp, etc. all provide the tracking you're looking for - how reliable it is is always kind of a debate, but they are the standards.
  21. Honestly, if you want fancy tooltips I'd recommend using Tippy - super easy and powerful.
  22. Things you'll need to do to get help: Describe what the code should be doing Describe what the code is doing instead Show us any errors you're getting in your browser Show your relevant code If it seems like the error could be a database problem, describe the data and its structure Explain what you've done so far to fix the issue(s)
  23. Do you have a question?
  24. To elaborate on requinix's point, JavaScript is client-side. That means it runs in the browser, so - for example - if the user clicks on something JavaScript can catch that action and do things to the elements currently on the loaded page without reloading that page in the browser. PHP on the other hand runs on the server, so the page needs to be refreshed so the data gets back to the server and can be acted upon. If you want to run a server-side process from the client, you'll need to use AJAX (today, the fetch() JavaScript function) to send the client-side information to the server for processing.
×
×
  • 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.