Show validation errors, well not today???? |
[eluser]jbreitweiser[/eluser]
My cut and paste error. Call the function something else like get_page_vars or what ever makes sense to you. The $this->get_content call inside the function is calling the function you already have to read the information from the database. I was writing it as if it was moved to the content_model class. And yes, you do need to hit the database each time the page is submitted unless you write all the values to a hidden field. I would read it from the database each time to avoid any security issues with cross site scripting.
[eluser]123wesweat[/eluser]
[quote author="jbreitweiser" date="1266577016"] The $this->get_content call inside the function is calling the function you already have to read the information from the database. [/quote] hmm, but that's exactly what function get_content already does. I am also not sure how i would get the right $content_id again? Sould i add this as a hidden field in the form??? Maybe i could do this in the controller Code: $data['showContent'] = $this->content_model->get_content($options);; instead of Code: $this->data = array ( But how would i echo the vars which haven't got the same name in View, like Code: titletag != content_title
[eluser]jbreitweiser[/eluser]
Your redone function is good. I would do it that way as well. Less code is better. You could add the code below to copy the strings you need to a new key in the array. I don't know your app but I would keep this bit of code in a separete function because you need to call it from both the show and send functions. No need to have the same code twice if you don't have to. Code: $data = $this->content_model->get_content($options); And you do need to have a hidden field on your form to pass the content ID back or bake it into the url.
[eluser]123wesweat[/eluser]
hi, i am slowly, slowly getting it. I have started another thread related to this as i am not sure how to "stay" on the same url after a form validation. In my example i indeed have a hidden field. city2go.net/test/banksy <- id1 city2go.net/test/futura <- id2
[eluser]jbreitweiser[/eluser]
Make you post tag have action="city2go.net/test/banksy/1". Use the URI class to get that segment. So in this example test is the class and banksy is the method you are calling. URI is a default class so you do not need to load it. refer to http://ellislab.com/codeigniter/user-gui...s/uri.html for how to write urls with parameters. Code: class Test extends Controller{ As for staying on the same url, I am assuming your form is posting back to the same url you called in the first section. If not I would think about doing it that way. Its easier to display to initial page and deal with the form submission in the same controller. Otherwise you will have messy redirects or other work arounds.
[eluser]123wesweat[/eluser]
hmm not quit how i have set it up /test/banksy is a seo url in routes.php i have Code: $route['test/banksy'] = "testForm/show_content/1"; So in fact i have a testForm class with a show_content method and i get the hidden content id just by Code: function show_content($content_id = 1) { About the staying on the same url, i am NOT () and yes i am looking into redirects. I am a bit confused when i give the form the same action i.e. test/banksy then testForm/show_content will be called each time. Should i make an conditional in method show_content to see if isset($_POST["submit"])??? the thing is as i am planning to have more forms i thought about using a form controller, now i am not sure.
[eluser]123wesweat[/eluser]
hmm, didn't know form validation could give me so much !#@$13. Anyhow still in my test site i do have a sort of solution but it doesn't look pretty in my testForm controller i have Code: function show_content($content_id = 1) { in view_test_mainD i had to add a conditional Code: if(!isset($msg)){ and in view_test_formD i have set the form action to Code: <?php echo form_open(current_url(), 'id="form"')?> going to have a cup of tea and come back to see if i understand it.
[eluser]jbreitweiser[/eluser]
OK. Are you flexible with the database structure. I think the hard coding in the routes table is the problem here. What if you could search by the book. So instead of $route['test/banksy'] = "testForm/show_content/1"; use $route['test/(:any)'] = "testForm/show_content/%1"; This would translate 'test/banksy' to "testForm/show_content/banksy" So you could search for banksy by using the uri class $book_name = $this->uri->segment(3); Then you could add a route for the submit form $route['test/submit/(:any)'] = "testForm/submit/%1"; $route['test/(:any)'] = "testForm/show_content/%1"; and could validate and update from the submit function. Does this make sence.
[eluser]123wesweat[/eluser]
hmm, i see what you doing but i do have some doubts with your suggestion mainly 1 Code: $route[‘test/submit/(:any)’] = “testForm/submit/%1”; 2 i don't like to get the content of the db by string, i am more likely to choose for id as it's unique. also when editing the content in the db banks y != banksy != btw i am not creating a search form. here's what i have so far Code: function show_content($content_id = 1) {
[eluser]jbreitweiser[/eluser]
I get the unique ID. The only thing I would change is the check for content_id. Do the search and then check if you got a return unless you want to restrict it to the 2 values. Code: function show_content($content_id = 1) { I would also separate the show_content from the form process with a route. It just makes it easier to track down problems and also keeps the different action seperate. But if what you have works for you then it is right. There is always more then one way to get work done. Code: $route[‘test/banksy/submit/’] = “testForm/submit/1”; |
Welcome Guest, Not a member yet? Register Sign In |