php-beginner Posted April 29, 2011 Author Share Posted April 29, 2011 So this means I have to cut the output from the processing and parse it within my presentation (html)? Or just set the doctype at top which also solves this problem? Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208086 Share on other sites More sharing options...
KevinM1 Posted April 29, 2011 Share Posted April 29, 2011 Look at my edit above. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208091 Share on other sites More sharing options...
php-beginner Posted April 29, 2011 Author Share Posted April 29, 2011 Ah ok, I will try to figure that out , Thankyou so far! Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208094 Share on other sites More sharing options...
php-beginner Posted April 29, 2011 Author Share Posted April 29, 2011 I don't understand how I could implement this in my code. However, I see that you use $error. But the errors are stored in an array so I can't echo it like that. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208421 Share on other sites More sharing options...
php-beginner Posted April 30, 2011 Author Share Posted April 30, 2011 This does also work but am not sure if this is allowed: I change the message class in my user class to public; I change the function where I "echo" to "return $this->errorMessages;" Now I add this in my registration script to check if the object has been set ... : <?php if(isset($user)){ if($user->message->messageStatus != false){ echo 'Oops...'; echo '<ul>'; foreach($user->error as $msg){ echo '<li>'. $msg .'</li>'; } echo '</ul>'; } } ?> This means that I can remove this code from my user class because this is already set on the registration script: <?php if($this->message->messageStatus != false){ // etc; } ?> This way I don't have to rewrite lots of code. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208599 Share on other sites More sharing options...
KevinM1 Posted April 30, 2011 Share Posted April 30, 2011 Instead of making $message public, keep it private and make a new method that returns the result of $message->messageStatus. Something like: public function isValid() { return $this->message->messageStatus(); } So, you'd use if (!$user->isValid()) { // error code } Much more concise, and it leaves your encapsulation intact. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208630 Share on other sites More sharing options...
php-beginner Posted April 30, 2011 Author Share Posted April 30, 2011 Great, Thankyou very much for all your help. I have only one question left: Is the way I make use of object orientated programming good? Or did I wrong interpreted the way objects should be handled? You would probably do it differently, but everyone has his own way I think. Anyway, I'm new to OOP and I hope I understand it quite well now. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208650 Share on other sites More sharing options...
KevinM1 Posted April 30, 2011 Share Posted April 30, 2011 You're at the beginning stages of learning OOP. You have an idea of the syntax, although you're still missing some pieces there (static methods in particular), and I'm sensing you don't really understand, or are even aware of, the ideas behind OOP in general. There's a lot more to OOP than simply wrapping things in a class and calling it a day. If you want to do OOP for real, then at the very least you should look at the following two books: PHP 5: Objects, Patterns, and Practice by Matt Zandstra - http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_1?ie=UTF8&qid=1304177284&sr=8-1 Design Patterns: Elements of Reusable Object-Oriented Software by the Gang of Four - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?s=books&ie=UTF8&qid=1304177303&sr=1-1 The second book, in particular, will open your eyes to some things. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208654 Share on other sites More sharing options...
php-beginner Posted April 30, 2011 Author Share Posted April 30, 2011 Okay, Could you be more specific of what I don't understand. What I know is that objects should be re-usable, thats what I'm doing. And if ever needed in other projects, I could simply use the classes that are already made and leave the classes I don't need. Thanks for your suggestions, I'll take a look at those books. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208663 Share on other sites More sharing options...
KevinM1 Posted April 30, 2011 Share Posted April 30, 2011 Okay, Could you be more specific of what I don't understand. What I know is that objects should be re-usable, thats what I'm doing. And if ever needed in other projects, I could simply use the classes that are already made and leave the classes I don't need. Thanks for your suggestions, I'll take a look at those books. There's more to objects than just making things that are reusable. Reusable code can be, and is, written in a procedural manner, too. A lot of the 'magic' of OOP actually lies in being able to change behaviors at run time. From what little I've seen, you're at an intermediary point. You know that modularity is good, and that objects can be composed (that is, an object can contain another object), but that's about it. You still need to learn about abstraction and polymorphism. You also need to learn some of the common patterns of object creation and interaction. That's where the two books, especially the second, come into play. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208668 Share on other sites More sharing options...
php-beginner Posted April 30, 2011 Author Share Posted April 30, 2011 Do you mean by "change behaviors at run time" that I shouldn't call my objects (like message, encryption, formValidator etc.) in the user class, instead call them on the registration script? So that all the objects doesn't form as one system in the user class, but as one system at run time. Quote Link to comment https://forums.phpfreaks.com/topic/234961-input-stays-in-form-after-submit/page/2/#findComment-1208743 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.