![]() |
Show validation errors, well not today???? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Show validation errors, well not today???? (/showthread.php?tid=27632) Pages:
1
2
|
Show validation errors, well not today???? - El Forum - 02-16-2010 [eluser]123wesweat[/eluser] pff, overlooking something in my view form i have a div Code: <div id="errors"> and in education controller i have Code: if(isset($_POST['addEducation'])) { What am i overlooking/?? Show validation errors, well not today???? - El Forum - 02-16-2010 [eluser]danmontgomery[/eluser] You're overlooking the need to provide details about your problem, such as what's happening vs. what you're expecting to happen Show validation errors, well not today???? - El Forum - 02-16-2010 [eluser]123wesweat[/eluser] @noctrum, yep you are right again. Ok, i will try to explain my little problem - User clicks on [add education] - form is displayed - if it doesn't validate show erros and form again (with previous values) - else go to overview education Now in the education controller i have a form function which loads the form view. I have created this function so i wouldn't have to repeat some general data Code: function form($action) { Code: if ( ! $this->dx_auth->is_logged_in()) { I seem to have a fix for my original question by using Code: if ($val->run() == FALSE) { Show validation errors, well not today???? - El Forum - 02-16-2010 [eluser]jbreitweiser[/eluser] EDIT: You already figured this out. In the first section your using a redirect when the validation fails. You should be showing the view again with set_value for all the form values so it is the same as when they submitted it. Since you redirect the form is reset and no errors are shown. Show validation errors, well not today???? - El Forum - 02-16-2010 [eluser]jbreitweiser[/eluser] Your solution looks good. I am not sure why you pass $action to the form function because you are not using it. Also, I would check the login before doing anything else. It really should be the first thing you do so no actions are taken by chance. I seems the form function is the last thing you call, so you have done all you actions by that point. Also, you might what to change the $data['msg'] = 'No access'; to a redirect to a login page. No reason to even show them the page if they don't have access. Show validation errors, well not today???? - El Forum - 02-18-2010 [eluser]123wesweat[/eluser] hmm, still having problems with the correct way to handle a form. The problem i have now, is the following From main.php i load a view file (view_book.php) with another view a form view (form_a.php). Here's a part of view_book code Code: <div id="errors"> Code: <form action="/form/send" > now the send function is just Code: function send() { 1/ How do i show the errors and form again in book_view I am again not getting the error_message 2/can routing be an issue?? 3/main controller loads all data from db to parse view_book $data, how can i make sure this $data is being parsed again when i submit the form and view_book is reloaded again??? btw just a simple form (not within a view or nested view) goes ok. still learing CI Show validation errors, well not today???? - El Forum - 02-18-2010 [eluser]jbreitweiser[/eluser] I think you need to remember that when calling the load->view function, you are basically #including the file at the current position. So the way you have the view set up is the view book with a form view included as well, it is still one page. Its not a seperate page within a page. So what you have to do when the form is submitted is load->viw("view_book.php");. This view will then include the form_a view as well. Since you are only reloading the form_a view, you are not getting the part where the errors are displayed. Show validation errors, well not today???? - El Forum - 02-18-2010 [eluser]123wesweat[/eluser] @jbreitweiser, tx i will try to remember that load->view is kinda "include" When i load-> view_book Code: if ($val->run() == FALSE) { i get the errors (amongst others) Code: A PHP Error was encountered These variables are set in main.php with function show_content(); Function show_content loads the meta, descr, content and VIEW file etc from the db and passed as an array so the vars can be used in the nested views in view_book.php In view_book.php i got another load view Code: <!DOCTYPE html> This my simplied show_content function Code: function show_content($content_id = 1){ and $showContent["content_tmpl"] = 'view_book' Now i don't have the Code: $showContent = $this->content_model->get_content($options); Should i use ob_start() etc Please, advice oh btw, between all the errors and the ridiculous looking page i do see the error messages. Show validation errors, well not today???? - El Forum - 02-18-2010 [eluser]jbreitweiser[/eluser] You need to get all the information again from the db. Seperate out the common variables from the action specific ones. Then add the specific variables, like the name of the included view, in the action function. Code: function show_content($content_id = 1){ This can be put in the model as well. Keep Your controller simple. Code: function get_content($content_id = 1){ Show validation errors, well not today???? - El Forum - 02-18-2010 [eluser]123wesweat[/eluser] so this means there is a "xtra" query each time the form doesn't validate?? is this correct in the get_content function?? Code: $options = array ('content_id' => $content_id); When do you think about using a recursion? my get content function Code: function get_content($options=array()){ tx man, gonna try your suggestion and see if i can get it to work. Quote:Keep Your controller simple.I will try, i always start simple but.... |