Welcome Guest, Not a member yet? Register   Sign In
Re-populate a page with multiple forms if one form fails validation
#1

[eluser]it.peds[/eluser]
First, thank everyone reading this.

A site that has a search form/widget shows on every page. In case of user is filling a different form, and suddenly he/she want to search something else; if the search returns no results, besides loading a error page, any suggestion for how to re-populate this page with both forms as before but with a error message?

I have client-site validation and ajax ways to solve this problem, but I would like to learn a way when javascript is turned off.

Feel free to leave any idea. Thank you for your help in advance.
#2

[eluser]dnc[/eluser]
The way I do my validations is this.

1. Say your form is at site/search. The do a

Code:
echo form_open('site/search');


to post the data back to self. This is equivalent to $_SERVER['PHP_SELF'];


In your model or controller that checks the query you need to check if form was empty or whatever and I would use:
Code:
$data['error_message'] = $this->session->set_flashdata('search_query', 'Error Message Here');

You will probably want a view that solely consists of your form or maybe a header view with the form so you will not reload the entire page on an error. Post the flash_data to the view. I hope this is clear to you.



#3

[eluser]it.peds[/eluser]
@dnc,

First, thank you very much.

I think you mean
Code:
redirect('controller/otherForm', 'refresh');
, right?

In this case, the un-saved data of the other form will not be re-populated.
#4

[eluser]dnc[/eluser]
[quote author="it.peds" date="1339796689"]@dnc,

First, thank you very much.

I think you mean
Code:
redirect('controller/otherForm', 'refresh');
, right?

In this case, the un-saved data of the other form will not be re-populated.[/quote]


Is there a reason you do not want to use the form validation class to re-populate the form?

Code:
value="<?php echo set_value('search_value');?>">

Why use refresh here, this is where you need to pass your flash_data
Code:
redirect('controller/otherForm', $data);
#5

[eluser]it.peds[/eluser]
@dnc,

My problem, as topic suggests, is when one form fails form_validation, how can I re-populate a page with multiple forms with all un-saved data and no javascript?

So far, using redirect(), I can re-populate all forms with saved data and error, but not unsaved one. Beware, un-saved data can be any forms on the page.
#6

[eluser]Sanjay Sarvaiya[/eluser]
For re-populate all forms.
You can do with passing POST data to view after form validation false.
Code:
if(count($_POST) > 0)
   $this->load->view('search_form', $_POST);
else
   $this->load->view('search_form);

may thats help you.




Theme © iAndrew 2016 - Forum software by © MyBB