/    Sign up×
Community /Pin to ProfileBookmark

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….

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMar 27.2014 — Not sure what your question is. Altho you do have an error in your div tag, the premise is valid.
Copy linkTweet thisAlerts:
@sulman8sauthorMar 27.2014 — 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?
Copy linkTweet thisAlerts:
@ginerjmMar 27.2014 — 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?
Copy linkTweet thisAlerts:
@sulman8sauthorMar 27.2014 — 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?
Copy linkTweet thisAlerts:
@ginerjmMar 28.2014 — 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?
Copy linkTweet thisAlerts:
@sulman8sauthorMar 28.2014 — i am using errorcheck=true; a booelen variable if it true then show otherwise false and submit form... more how to shorten the code?
Copy linkTweet thisAlerts:
@ginerjmMar 28.2014 — 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).
Copy linkTweet thisAlerts:
@sulman8sauthorMar 28.2014 — can u elaborate with a simple example .. i did not understood..
Copy linkTweet thisAlerts:
@ginerjmMar 28.2014 — What part don't you understand?
Copy linkTweet thisAlerts:
@sulman8sauthorMar 28.2014 — 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 ....
Copy linkTweet thisAlerts:
@ginerjmMar 29.2014 — 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???
Copy linkTweet thisAlerts:
@sulman8sauthorMar 30.2014 — because i will display at the front of each field thats why...
×

Success!

Help @sulman8s spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...