Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery placeholder in IE passing validation…

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #34860
    standuncan
    Member

    I have a small form where I cannot use labels, so I am using placeholders as labels. For the older browsers (this site has old IE users) I have installed a jQuery snippet to use the same placeholders, however now those placeholders pass the validation. Anyway around this?

    form:





    php



    if(!empty($_POST)){

    $name = stripcleantohtml($_POST);

    $errors = array();

    //Check the form fields
    if(empty($name)){
    $errors = '*';
    }

    jQuery



    if (!("placeholder" in i)) {
    $("input[placeholder]").each(function () {
    var self = $(this);
    self.val(self.attr("placeholder")).bind({
    focus: function () {
    if (self.val() === self.attr("placeholder")) {
    self.val("");
    }
    },
    blur: function () {
    var label = self.attr("placeholder");
    if (label && self.val() === "") {
    self.val(label);
    }
    }
    });
    });
    }

    #89454
    standuncan
    Member

    Ughh, I never see the sections when I post, they always end up int he wrong spot :/

    My bad!

    #89539
    standuncan
    Member

    Yes, in IE due to the jQuery placeholder script, the actual placeholder “Name” (and others) pass validation, since I am only checking to see if the input has a string in it. This does not happen on email, because I am also checking to see if it is a valid email. I’m not 100% sure I understand what you’re saying. Can you explain it again or show an example for me please?

    #89586
    standuncan
    Member

    This site was pushed live, (not up to me), and it has an adwords account, so it is getting traffic now. Some of the forms coming in are:

    Name: John Doe

    Phone: Phone <– placeholder

    Email: [email protected]

    etc. Any help would be appreciated.

    #89603
    Mottie
    Member

    I’m confused, if it is PASSING validation. then what is the problem?

    If you mean that is isn’t passing, then maybe put the placeholder content into the “alt” attribute, and if placeholder is supported in the browser, then copy the alt value over to placeholder.

    Input

    Script

    // check if the browser supports placeholder
    if (typeof(document.createElement('input').placeholder) !== 'undefined'){
    // yes it does!
    $('input[alt]').each(function(){
    this.placeholder = this.alt;
    });
    } else {
    // no it doesn't, add your placeholder plugin here
    // but pull the placeholder value from the alt
    }
    #89716
    standuncan
    Member

    I tried what @TT_Mark said after a lot trying to figure out how and I came up with this, but don’t know if it is correct? It seems to be working though…

    Any thoughts?

    html:





    php:



    if(empty($name)){
    $errors = 'Enter';
    } else {
    if (is_string("Name")) {
    $errors = 'Enter your name';
    }
    }


    #89719
    standuncan
    Member

    and for some reason this was working on 1 input, but not another, so then I tried this and it seems to be working for the most part too. Are either of these even correct?



    if(empty($phone)){
    $errors = '*';
    } else {
    if ($phone = "Phone") {
    $errors = 'Enter your phone';
    }
    }

    #89696
    standuncan
    Member

    Just in case anyone further reads or cares lol

    I got it right above pretty much, but had the wrong assignment operator instead of the comparison operator.

    Got it working now :D



    if(empty($name)){
    $errors = '*';
    } else {
    if ($name == "Name") {
    $errors = '*';
    }
    }

    #89725
    Mottie
    Member

    YAY!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.