Object Oriented PHP #13 - Validation Class (part 2)

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Hey gang, in this PHP OOP tutorial we'll flesh out the rest of our form validation class with methods for validating different form fields.
    ----------------------------------------
    🐱‍💻 🐱‍💻 Course Links:
    Course files - github.com/iam...
    🐱‍💻 🐱‍💻 Other Related Courses:
    + PHP Tutorial for Beginners - • PHP Tutorial for Begin...

КОМЕНТАРІ • 33

  • @ProgrammingwithPeter
    @ProgrammingwithPeter 5 років тому +10

    This is so useful for beginners! Great job, on making custom validations!

  • @rolandjethrosuyom478
    @rolandjethrosuyom478 3 роки тому +3

    Thanks shaun for this wonderful tutorial. I used this class validators and add field to check using your pizza project in your PHP for beginners tutorial. Also, I added an update page so that users can update the pizza they added.

  • @TechTutorialCN
    @TechTutorialCN 4 роки тому +2

    The most excited and clean explanation for beginners.

  • @bobianoano4235
    @bobianoano4235 2 роки тому +2

    salut et un grand merci pour tes videos , je mrts juste une mise à jours : En raison de compatibilité ascendante, la fonction array_key_exists() peut aussi retourner true si key est une propriété définie dans un object, fourni comme paramètre array. Ce comportement est obsolète à partir de PHP 7.4.0, et a été retiré à partir de PHP 8.0.0.
    Pour vérifier si une propriété existe dans un objet, property_exists() devrait être utilisé.

  • @shuttereff3ct593
    @shuttereff3ct593 4 роки тому +1

    A real life example here, thank you!

  • @perianka
    @perianka 4 роки тому +4

    why if data is also an array you don't have to declare that when you give the class properties? like $data = []; ?
    is there a difference between trigger_error and just echoing the string saying there's an error?

    • @marky1756
      @marky1756 6 місяців тому +1

      same thought

  • @izzatullokanoatov370
    @izzatullokanoatov370 5 років тому +2

    Thank you very much brother . For your effort and clear explanation. Thumbs up :)

  • @shaikhasad2911
    @shaikhasad2911 4 роки тому +2

    thank you very much for this, but i didn't understand how you're passing values to addError function and the constructor? asking as a beginner. thank you agian!

  • @AndrewRMillar
    @AndrewRMillar 4 роки тому +2

    You are going to have a problem with that regex if you have weird letters, like "â" or "ë". But English doesn't use many of those. Through me for a loop once.

  • @Windtalk3r
    @Windtalk3r 3 роки тому +2

    I think I went to a website the other day that used your preg_match for their password requirements. I could not enter a password that had more than 12 characters. :)

  • @hadisergan1
    @hadisergan1 4 роки тому +1

    brother thank you very much you are doing a great job.I am a big fan of yours.

  • @ismailhossain2059
    @ismailhossain2059 4 роки тому +2

    If submitted value is ok then what is process to save it into Database? Coulde show that too?

  • @sonoftroy8572
    @sonoftroy8572 4 роки тому +1

    I have a question about the array-key-exists method. does it convert the values of the $_POST data or the $field array values into keys? or am I looking at the $_POST array wrong. I'm thinking the values inside the $_POST array come from the inputs that are submitted by the form... and the keys are zero indexed. or should I be asking what part of the submitted data becomes the key? is it the $_POST array or is it the $field array... i'm not too sure. other than my question, I really learn a lot from your tutorial and I can't thank you enough... I subscribed a long time ago and always a thumbs up from me.

    • @vigneshkarthikeyanr4374
      @vigneshkarthikeyanr4374 4 роки тому +1

      I have a similar doubt.... If the function of that 'array_key_exists' is to check if it exists then why check if its empty???... I don't even know if I have understood these correctly... Explain... Thanks in advance @Son of Troy

    • @perianka
      @perianka 4 роки тому +1

      I have the same question, I dont quite get how that function is working but I think each $field represents each key (email and username) and I guess that $data (that stores $post_data) is an array like ('username' => 'irina123', 'email' => 'irina@gmail.com') but I don't know where that array comes from.
      UPDATE: It's been 45 minutes since I posted this and I think the best way to understand it is before doing anything, in the index.php file, var_dump($_POST) so you get what's inside, I did it and what I got is:
      array(3) { ["username"]=> string(6) "irina123" ["email"]=> string(21) "irina@gmail.com" ["submit"]=> string(4) "Send" }
      meaning that there are keys called username, email and submit and each one has a value

    • @sonoftroy8572
      @sonoftroy8572 4 роки тому +2

      Irina Lyrics: yea I took a closer look at the functionality, php says array-key-exist checks the key of one array for existence . However in this situation it’s checking two separate arrays so it’s sort of a hack. The form input name fields are passed into the construct then a separate array has matching string element. The index of the separate array get converted into the form name input field somehow showing existence of a key... yea it’s crazy but now we know array-key-exist can be hacked just by having matching string elements that comes from a separate array

  • @villastube
    @villastube 3 роки тому

    Very nice explained

  • @issaissifou4959
    @issaissifou4959 Рік тому

    Thank you so much!

    • @NetNinja
      @NetNinja  Рік тому

      You're very welcome Issa!

  • @juantolentino4562
    @juantolentino4562 5 років тому

    Sensei, this is Awesome!!

  • @omniversal4739
    @omniversal4739 3 роки тому

    What if I have fields that belong to the same name let's say I have multiple options (radio buttons) which are named with the same input field name (i.e.: "gender"), is the array_key_exists() method gonna yell at me that one of these fields is not present in data even if I plug it into the $fields variable array as the keys would have a the same name?

  • @AndrewRMillar
    @AndrewRMillar 4 роки тому +4

    filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW)

  • @nazarttgoh333
    @nazarttgoh333 4 роки тому

    THANK YOU VERY MUCH !

  • @YashkumarMavani
    @YashkumarMavani 4 роки тому

    Please add some tutorial for file handling using oop

  • @art1co
    @art1co Рік тому

    why he put return; alone with no following code?

  • @dididudu2072
    @dididudu2072 Рік тому

    what is the construct for?

  • @raj080288
    @raj080288 3 роки тому

    what is the difference between "return;" and "reuturn true;"?

  • @coolwaterdvr
    @coolwaterdvr 3 роки тому

    🙏🙏🙏🙏🙏

  • @FarryEntertainment
    @FarryEntertainment 3 роки тому +1

    So if a form contains 20 fields, you have to do this 20 times? How is this the best approach?

    • @AndrewT34pot
      @AndrewT34pot 2 роки тому

      In a way it's the only approach, assuming that every field is unique. if they're not then you can probably get away with using the same method, but that's usually not the case if you have 20 fields

  • @MustafaBirsoz
    @MustafaBirsoz 3 роки тому

    🥷 🥷 🥷

  • @user-testo21347
    @user-testo21347 2 роки тому

    public function validateForm(){
    foreach(self::$fields as $field){
    if(!array_key_exists($field, $this->data)){
    trigger_error("'$field' is not present in the data");
    return; // *****why it is necessary ?******
    }
    }
    $this->validateUsername();
    $this->validateEmail();
    return $this->errors;
    }
    what is the role of the return statement?