Jump to content

justsomeguy

Moderator
  • Posts

    31,575
  • Joined

  • Last visited

  • Days Won

    77

Posts posted by justsomeguy

  1. you are sure after validating the form empty space would no longer be in the database

    You're the programmer.  If you don't want to insert empty rows in the database, then check if the data is empty before inserting.  Doesn't that sound like it would prevent empty rows?

    Seriously, a programming language is just the way that we tell computers what to do.  You're the one telling the computer what to do.  If you don't want it to do something, then make it not do it.  It really is that simple.

  2. Well, it can get a whole lot of possible values.  You'll need to understand the parts of it.  [0-9] means any digit, if it's followed by a plus sign it means 1 or more digits.  | means "or".  A number in brackets, like {2}, means 2 of the previous character class.  There should be plenty of regular expression references online if you want to look up specific things, or if you have specific questions you can ask here.

  3. For deprecation, when something is deprecated the developers are signaling that it is going to be removed in a future version to give people time to move away from whatever was deprecated.  They can still use the current version and whatever was deprecated will still be supported, but it's going to be removed soon.

  4. It's probably inserting blank rows because you don't do any validation, you don't check if anything was submitted before inserting, you just insert.  All of the code after you close the database connection isn't doing anything, you have a typo in it but the only thing you do is run a function on things that would be in post.  You don't do anything after doing that though.

    You should check to see if the form was submitted before inserting data.

  5. Spammers will scan for unsecured email forms and try to use them to send whatever email they want.  A basic form probably doesn't have a lot of anti-spam protection like using a captcha or another method to identify legitimate users versus spammers.  If you don't know anything and don't want to learn how to do it you might just want to hire a programmer to add a secure contact form.  If you're using something like Wordpress there should be quite a few plugins for contact forms.

  6. there are other things that can be used in place of window to make the alert appear differently. Is this correct?

    No, that's not correct.  All code in Javascript runs in a specific scope.  The scope is where it looks for defined functions and variables.  By default the global scope is the window object, so anything defined on the window object is available everywhere unless it's overwritten.  You can see scope in an example like this:

    var a = 'foo';
    
    console.log('global a:' + a);
    
    function func1() {
      console.log('func1 a:' + a);
    }
    func1();
    
    function func2() {
      var a = 'bar';
      console.log('func2 a:' + a);
    }
    func2();

    If you run that and look at your browser's console, you'll see it print the different values.  The first 2 are the same.  Inside func1, since a is not redefined, it uses the global variable a.  In func2, a is redefined as a local variable, so it uses that instead.  That is scope, where things are defined.

    Since the window is the default scope, you can refer to those variables and functions anywhere.  So window.alert is defined to show an alert box, but since window is the default scope you don't need to use it, you can just write alert and the browser will still go up the scope chain looking for a function called alert until it gets to the window object.  If you've seen document.getElementById, that's another example.  The document object doesn't live by itself, it's also a property of the window object.  So you could also write window.document.getElementById.

    So, no, you can't just substitute something else for window and expect it to work.  It will only work if you've defined a function called alert on that object also:

    var obj = {
      alert: function(text) {
        console.log(text);
      }
    }
    
    window.alert('test1');
    obj.alert('test2');

     

  7. If you're required to use Progress, it looks like you may need to use an older version of PHP.  I would contact them and try to find out what their plans are for support.  If it's difficult to get in touch, I wouldn't use them.

  8. It sounds like you're not canceling the form submit event, so it's defaulting to the current page and the get method.   You can verify that with an alert or console.log statement.

    Redirecting the ajax request isn't going to cause the browser to automatically redirect the main page, it just redirects the ajax request.  If you want to redirect the user after the ajax response comes back then you need to redirect them using Javascript.  You can have the PHP code return the URL to redirect to if it might change, and then actually redirect using Javascript.

  9. That means there is a syntax error in the code.  Your browser's developer console includes an area where you can look at all of the Javascript source code and set breakpoints to see if it's being executed.  If the code is minified and all on one line that doesn't really help with breakpoints though.

  10. A lot of the behavior you're seeing might be browser-specific.  I would certainly never refer to an element just by its ID alone using something like input1.value, because eventually you're going to give an element an ID that already exists in the window object and then that's not going to work any more.  getElementById always works.  You can also use querySelectorAll to use a selector to find groups of related elements the same way you use a selector in CSS.  I wouldn't use form.elementName either, not all browsers may support that.  A form object has an elements collection which specifically contains the controls in the form.  If your form has an input with the name "name", then does form.name refer to the name element or the form's name attribute?  You want to avoid things like that, so if you want to iterate through the elements in a form then use the form.elements collection.

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement

    When in doubt, look it up on MDN and see what the specifications and browser compatibility say.

    The best code is code that is easy to understand.  It doesn't matter how many characters are in document.getElementById, when you see that you know exactly what it's doing.

×
×
  • Create New...