Jump to content

requinix

Administrators
  • Posts

    15,236
  • Joined

  • Last visited

  • Days Won

    428

Posts posted by requinix

  1. I've hidden your, let's say, unconstructive post.

    Since I'm an actual developer who wants to see other people learn and grow so they can become actual developers, I don't tell people something that they can copy and paste into their code. I give them information and hope that they're willing to put in the time and effort into understanding what it is they're doing. So thank you for your feedback but I'm going to continue calling out instances of people writing 1990s-era Javascript without understanding what they're doing and why it isn't working. After all, there's a very simple and fundamental principle in play right here: if you're going to work with something, the least you can do is try to learn more about it.

    If you want something to tell you the answer so that you can copy and paste it into your code then you already know about ChatGPT, but did you also know you can do things like throw terms like "javascript onclick modern way" into Google and it'll spit out some AI nonsense of its own that is actually occasionally useful?

    image.png

     

    I tend to assume people will invest time into a thread so I tend to avoid writing long knowledge-dump replies - because it's too much information at once, and also becomes sometimes it turns out to be a waste of my time - but had this thread continued, maybe it could have gone like this:

    Q: Okay, so I understand that onclick is just executing code, but what do you mean it isn't returning a value? The return statement is right there.
    A: Yes, the return statement for ConfirmDelete, but there's no return statement for the onclick itself. Like I said, it is basically a function even though it's written as an attribute in the HTML, and it's that function that needs to return true/false.

    Q: So is that the modern way? Returning from the onclick?
    A: No, the modern way is to not use any of those on* attributes and instead attach events through Javascript. As in, when the page loads you run a bit of Javascript that attaches events to whatever elements it needs to using addEventListener.

    Q: I read up on addEventListener and switched to using it, but now when I click the button, I get the confirmation and it still submits the form. [Insert code here.]
    A: That's because event handlers done through addEventListener work a little differently. You can't just return false to stop the event - the code needs to be a little more sophisticated in that it explicitly says "stop the event"... except you don't actually need that. There's another way that (IMO) is simpler to work with.

    Q: What's the other way?
    A: Instead of making the button be a submit button, make it be a regular button. And instead of making the event handler stop the form from submitting, it directly makes the form submit. Meaning instead of "if not confirmed then stop" it's now "if confirmed then submit". Which probably makes more sense from a human-being angle: you typically think about these things in a proactive way like "if I click the button then I want to get a popup asking me if I'm sure I want to submit the form" (which the new code would say) and not the reactive way of "if I click the button then submit the form, but only first after asking the user if they want to" (which the old code says). It's a subtle distinction, and admittedly not one that's relevant all the time.

    Q: I don't follow. What would I do differently?
    A: Change the button to a regular "button"-type button, keep with the addEventListener, but change your popup thing to be "if (confirmed) { submit form }". [Insert code here.]

    Q: That sounds complicated. Why should I do all this when I could have just stayed with onclick and returning true/false?
    A: Because if you ever want something fancier than the confirmation popup you have now, the onclick+return pattern simply won't work. You can only do that when the code can make an immediate determination of whether or not to continue with submitting the form. If the confirmation was any sort of Web 2.0-style modal then it couldn't return immediately and you'd be forced into this alternate scheme. You might as well get used to the pattern now so it'll be easier to remember when you need it. Besides, it's not like it's a huge amount of work, and the additional work compared to onclick+return isn't wasted because you're improving the quality of the code as you go. And quality of code directly translates into quality of life.

    • Great Answer 1
  2. The "expert sex change" website still exists? Wow. That's amazing.

    The way for this (dated) design to work is that onclick has to return true/false. Right now, all it does is execute a function. Yes, that function returns true/false itself, but nothing happens with that value. It's just like writing

    function onclick() {
      ConfirmDelete();
    }

    You should try to do Javascript the modern way, which is "modern" for very good reasons, but if you won't then you fix this problem by making the onclick code "return" a value.

  3. Their tech support is exactly the place to ask. Because this is going to be an issue related to server configuration, which we can't see - but they can.

    A new host will have two major differences: different file paths (potentially) and different PHP settings. One of those is almost guaranteed to be the explanation.

  4. Where is the printer? Is it connected to the client or to the server?

    If it's connected to the client then the only thing you can do is present a print dialog. The user will have to choose the printer (potentially) and hit the button to print.

    If it's connected to the server then you can use a library to have PHP print the page. The details of that depend on what you're printing...

  5. The simple answer is probably also obvious: if you don't want to show the form under certain conditions (like after the form was submitted successfully) then don't show the form under those conditions.

    There's a bunch of different ways to go about it, but the one thing they all have in common is that there's an if statement that checks whether or not you want to show the form, and if you do then it shows the form. For example,

    if (/* show the form */) { ?>
    
    (the form)
    
    <?php }

     

  6. (foreach isn't a function)

    It'd be easier to show if you posted the rest of the code instead of just a couple lines, but basically, replace the while loop with a foreach loop, and then add into it a little logic for $errMess.

    If that still doesn't make sense, post what you came up with (as well as the original code) so we can see what happened and not have to guess about it.

    • Like 1
  7. That was a great, detailed answer that gave me a lot more information to work with than what you first posted.
    Knowing what you're doing with the session, more than just "start a session and set session variables for different things", tells me about the sorts of practices you might be following, how they might work and might not work, and gives me a good foundation I can use to ask you questions that will make more sense.
    Knowing that you're trying to understand the developer tools but still aren't quite able to work with them, more than just "How x 3", means I feel more invested in helping you to learn. Like I said before, those tools are invaluable when it comes to a lot of web development work, and there's a high likelihood that those tools will be able to explain what's going wrong.

    But knowing that you've tried this with Firefox and that it doesn't work no matter what is the best part. Web browsers don't just randomly decide how they will work. If Firefox doesn't work but Chrome might, that strongly suggests something is wrong with what you're doing - and I mean that in a very general sense of "you are doing a thing and there's a problem with it", as opposed to "you are doing a thing and Chrome isn't working correctly".

    1. If you haven't done it yet, the first thing to check is the console in the developer tools. I believe F12 on any browser will pull them up. It should give you some sort of collection of tools or tabs, and one them should be clearly marked as Console. Have the tools open as you log into the admin (like in Firefox). Do you see any errors or warnings?
    2. There's also a Network tab. If there's no messages then (that's surprising, but) you'll have to look a little closer at what's happening. Provided the tools were open when you logged in, the tab should show a request to your login page or AJAX endpoint or whatever. That's where cookies may have changed. Open up the information for the request and check the Response headers. What does it say for a Set-Cookie?
    3. It might not have anything. That's fine. Now check the Storage tab and look for your site's cookies. One of them will be the session cookie, probably named like PHPSESSID. What are the settings for it? (Specifically, the path.) Also, what are the URLs for your login and admin pages? (Specifically, the path portion.)

  8. PHP doesn't care what browser or operating system you're using to view pages. Your problem is going to be either (a) settings in the Ubuntu browser that prevents it from accepting the session cookie, or (b) a problem with the session cookie where the Windows browser is accepting it incorrectly but the Ubuntu browser is rejecting it correctly.
    Actually there's a third possibility: a difference between how you're using the two browsers that is important but you don't know about and/or aren't mentioning. Such as a different hostname, source IP address that somehow matters, some sort of Windows authentication mechanism...

    1. Check the network responses and confirm you're receiving a Set-Cookie on at least the first visit
    2. Check that the cookie is being remembered by the browser/not being rejected for some error that should have been logged somewhere/isn't immediately expiring/something else
    3. Check that the cookie is being sent in additional page requests

    99% of the time the problem will show up in one of those three steps.

  9. I don't remember if Intelephense provided the feature or not. In fact I might not even have tried it with PHP - maybe it was another language. But I assume the concept works the same way everywhere.

    But yeah, the hover or autocomplete list has always been sufficient for me. Oh well, whatever works best for each person.

  10. 38 minutes ago, gizmola said:

    Not sure why you would want to disable the hinting feature,

    It might work a little more cleanly in PHPStorm, but when I tried it in VS Code, I found it much more complicated to try to select text or read through code when the editor was injecting those things into the view. Maybe if they weren't inline, though I can't imagine how not, they might be nicer for me...

    But I'm also a proponent of the idea that you should be able to tell what the parameter is, be that through a variable name or an obvious literal value (or a constant...), and if you can't tell then you should do something about that.

    // this is obvious on what the parameters are
    password_verify($password, $hashedPassword)
    
    // this is not
    password_verify($value, $row[1])

     

    • Like 1
    • Thanks 1
  11. The code you posted is not using alert().

    Is it possible that the code you posted is meant to return a message to display? And since you're returning a message that looks like HTML, it is alert()ing that HTML? If so then the code you need to fix isn't what you posted...

  12. 4 hours ago, RemiGuru said:

    Ok, now i will explain what is going wrong.

    And where is that? I'm guessing that you're expecting to see those two events in your version of the code but, according to that one screenshot, are not.

    Without seeing code or data, I'm also guessing it's going to be one or more of:
    - You don't have the data for the events
    - The data for the events is present but incorrect
    - The query to retrieve the data is incorrect
    - The query is correct but the code to display the data is incorrect

  13. 2 hours ago, PeterBubresko said:

    I have understood or misunderstood that a framework is a platform or an application developers are using to program or set up a site or a script like VS Code or Dream Weaver etc.

    Misunderstood.

    Frameworks are a bunch of code that other people wrote to do stuff. Using them saves you the time of having to write your own bunch of code to do stuff. They do so much stuff that the intention is you take what they provide as a foundation and then add what you want.
    There's also libraries, which are a bunch of code that other people wrote to do stuff that saves you the time of having to write your own code to do stuff, but they're much smaller in scope than frameworks. They're basically about solving small individual problems, so using libraries means you don't have to solve those same problems yourself and you can focus on more important issues.

    There is overlap between frameworks and libraries. The distinction is in how they get used: are you taking a bunch of stuff and adding more, or are you using stuff to create other separate stuff?

    VS Code and Dreamweaver (if anyone still uses that) are "integrated development environments", but everybody just calls them IDEs. IDEs are glorified text editors, in that they let you type stuff into a text file just like any simple text editor does, but IDEs also have tons of features dedicated to dealing with code and so are much nicer to use than text editors. Like they can be aware of language syntax nuances and tell you when you wrote something wrong, while text editors might be able to do a little bit of that but would care more about checking your spelling.

    2 hours ago, PeterBubresko said:

    If I read about a framework on another website a framework is like a template. Can someone please tell me what it is.

    I don't like "template" as a metaphor. A template is about taking something and supplying a few bits here and there and you're done. You go to some blog creator website (coughwordpress) and they'll give you a template for a site: you set a name, colors, images, whatever, but all you're doing is customizing the same basic thing that everybody else is using.
    This forum is basically a template because we installed Invision Power Board and customized it a bunch.

    A framework is about you having a starting point for actually building something - not just customizing. You write code to do things, you implement features, you make decisions about how things work, and so on. Making a complicated website involves many different things, and frameworks have a lot of that designed for you so you don't have to make it all yourself.

    2 hours ago, PeterBubresko said:

    There is also this with controls. Is this a script that will operate in several places or be called on several times? To save time, this is put into a separate file that is called on from different places multiple times. What is the right thing here, and am I completely out of my mind? I am confused about this.

    Where are you seeing "controls"? That typically means things like text boxes and buttons and links, like right now I'm typing into a "textarea" control that has a bunch of formatting button controls at the top and a "submit" button control below it. But people don't normally use the word "control" much these days.

    I think maybe you shouldn't worry much about what a control is. It's such a generic term that it doesn't really say much. "Text box" and "button" and "link" are specific types of controls, and talking about those is much easier (but also kinda off-topic from what we're talking about now).

    • Thanks 1
×
×
  • 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.