dcsimg
www.webdeveloper.com
Results 1 to 13 of 13

Thread: How to call validation errors using class object and display at the front of field?

  1. #1
    Join Date
    Mar 2014
    Posts
    70

    How to call validation errors using class object and display at the front of field?

    is this ok

    or any other way?

    <label>Name</label><input type="text" id="name" name="name" value="<?php echo $name; ?>" /><br />

    <div="error"><?php echo $object->error['name']; ?></div>

    please help me....

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    Not sure what your question is. Altho you do have an error in your div tag, the premise is valid.

  3. #3
    Join Date
    Mar 2014
    Posts
    70
    i just create an class object then call the error variable that have an array... so i want to call if it is required please tell me this is ok or not?

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    Without knowing what you have in the method I have no way of answering you. Frankly it sounds like you should be determining if there is an error before sending the output and if so, sen the error message instead of a call.

    And - you really want to use a div tag to display the message?

  5. #5
    Join Date
    Mar 2014
    Posts
    70
    i am using <span>error</span> front of each field so when there would be an error so it will show to screen.. i just only want to know <?php echo $object->error['name']; ?> is this way right to call the variable? if so then i will have to do same for all fields..
    <?php echo $object->error['name']; ?>
    <?php echo $object->error['pass']; ?>
    <?php echo $object->error['email']; ?>
    <?php echo $object->error['lastname']; ?>
    <?php echo $object->error['age']; ?>
    <?php echo $object->error['dob']; ?>
    right?

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    If that is how you are getting errors then that code (while messy) will work.

    I assume you are just automatically re-sending the user's screen back to them regardless of whether there are any errors or not, or do you have a way of recognizing if ANY errors are present?

  7. #7
    Join Date
    Mar 2014
    Posts
    70
    i am using errorcheck=true; a booelen variable if it true then show otherwise false and submit form... more how to shorten the code?

  8. #8
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    My personal phobia is to use php tags in my code. One is enough for a script usually. In your case, you apparently are doing some kind of call to check your inputs for errors, then when you create your output html you make another call (in php/out of php) to get the error message. Me - I would capture the error messages and then output them instead of making another call to generate the message. That can then be done by simply including the php var in the html code using a heredocs (look it up).

  9. #9
    Join Date
    Mar 2014
    Posts
    70
    can u elaborate with a simple example .. i did not understood..

  10. #10
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    What part don't you understand?

  11. #11
    Join Date
    Mar 2014
    Posts
    70
    i just want to know is this good way <?php echo $object->error['name']; ?>
    <?php echo $object->error['pass']; ?>
    <?php echo $object->error['email']; ?>
    <?php echo $object->error['lastname']; ?>
    <?php echo $object->error['age']; ?>
    <?php echo $object->error['dob']; ?>
    to call a public variables again and again or any good practice ....

  12. #12
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    The code is fine. Your use of <? and ?> after each line of code is silly. Why do you keep going into php mode and then back out and then back???

  13. #13
    Join Date
    Mar 2014
    Posts
    70
    because i will display at the front of each field thats why...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles