I have a table of items listed in dashboard in which there's a menu to add certain data to it. So let's say I click item 1 to add data, I'll be directed to a page with link like item/01/add-data/. In this page, there's a form that you need to fill in corresponding to item 1. The problem is it's fine if the input can pass the validation form, but if it can't then there's certainly an error message shown right? Here's my problem.
I make it like this in the item controller
if ($this->form_validation->run() == FALSE){
$this->session->set_flashdata('flash_data', validation_errors());
redirect('item/add_item');
}
And add_item is a function in item controller. So there's that. But the problem is in redirect, it'll always reload a new page and show a blank page saying 'no data' with the error message (no form is shown). How do I reload the same page form as also put the error message above it? thanks.
Related
I have a web page that loads all the data from a mysql database called datalist.php
From this page I can edit record by record with a button that redirects you to an editdata.php page adapted to the fid of the record.
Once edited as they want to see the changes, I don't redirect them to the main one letting them see the changes and simply clicking back or with a button they return to the datalist.php without any problem.
The button is this
echo "<p id='parrafo'><a style='padding:1px 20px'class='button rounded-0 primary-bg text-white w-0 btn_1 boxed-btn' href='javascript:history.back() '><--</a></p>";
PROBLEM
I added a search engine where the displayed data can be filtered.
When they use the search engine from datalist.php, I direct them to a page called search engine.php where, through a post method, I store what they are looking for in a variable and the data that users want appears.
But when they edit a filtered record, it is edited without problems, but when they go back, they return to the search engine.php and the message appears:
"Confirm form resubmission In order to display correctly, this web page needs the data you entered earlier. You can submit that data again, but that will cause the page to repeat all previous actions. Press Reload to submit the data and display the page.
Hit the page refresh button to resubmit the data needed to load the page."
Of course, if they update, they come back when the filtered data comes out.
Isn't there any way to store the variable used in the search so that when I go back I don't get this error or any solution??
simple! when user will submit form for that variable instead of making post request
option1: just use get request __url__?variable=... but this will not remember the variable when you go back
option2: store the variable in the cookie and just go to next page (eg. window.location.href = '...';). and in next page access the cookie from php.
If you are wanting to show the form to the user as a confirmation, but without the possibility of another post, then remove the form element and the button. Display all other boxes as they are (with the values populated from the POST array).
And display another message telling them that it has been successful.
You are using PHP, you can achieve this easily with it. If you are unsure, then post a short version of your code in a separate question.
I know there are similar kind of questions posted on this site. But I have different issue. Please look at the below description once. I have already looked in all the answers, but did not get any useful from that.
I have a 'View' say View1, where a Search form is available. In the controller named 'Home' , there are 2 functions named as 'find' and 'advsearch' which direct to 'View1' only.
Suppose currently we enter 'home/find' in URL, 'View1' is displayed.
If I submit 'Search Form' which is on View1, form will direct to 'home/advsearch' and the result is displayed on the same view 'View1'.
If I click back button of browser, it again goes to url 'home/find' and display 'View1'. Which is expected and working fine.
Issue: Submit 'Search form' multiple times, It keep showing the searched result on View1. But when we click the back button of browser. It shows URL 'home/advsearch' but throws error message "Confirm form resubmission".
How can it be handled, so on clicking back button, It should display data but not that resubmission error message?
I was facing same problem and foud out the easiest solution. most probably the right way to handle search requests. Just change the search form's method to GET and pass the keywords in url.
to recieve the form data:
$this->input->get('input_name');
I have a custom page that submits a form to another custom Wordpress page. I need to check the userID on this page, so I do this :
$user_ID= get_current_user_id();
When i echo that variable I get 0. HOWEVER, if i access the page directly (without submitting the form) it shows the correct userID.
To make it stranger, when i submit the form my admin bar will disappear as if i wasn't logged in, again, if i access the page directly the admin page will appear.
What could be happening when i submit the form that will cause this?
I should mention the page im submitting to is a copy of page.php with a few lines of code to submit the variables to a database. Anybody have some suggestions?
I am trying to do a register form with CodeIgniter. My form is somewhere in the middle of my page and it has an anchor attached.
I want the page to load to that anchor in case the sent form failed, so I am using redirect(myweb#register) but the form errors are lost in the proccess, when they should be displayed after making the attempt to send this form.
What can I do?
If you are doing a redirect the one way of keeping the errors is to use flash data: http://ellislab.com/codeigniter%20/user-guide/libraries/sessions.html
$this->session->set_flashdata('error', 'message');
redirect(myweb#register);
Rather than redirecting, you should let the page display as usual so your error display, then use something like jQuery ScrollTo to go back to the anchor.
I have a form which once the Submit button is pressed, it goes to a blank page and returns any error messages on that blank page. However I have a website template and I wish that my script is run, and returns the the page which did the action POST and puts any error messages on that page.
Example of what is happening:
PAGE REQUESTS POST ----> SCRIPT RUNS ---> RETURNS ERROR MESSAGE
What I want it to do is:
PAGE REQUESTS POST ---> SCRIPT RUNS ----> GOES TO THE PAGE WHICH REQUESTED POST ----> SHOWS ANY ERROR MESSAGES WHICH THE SCRIPT PICKED OUT.
Sure you can, just set the Action of your form to the current page. Then the $_POST will contain all the values the user filled in the form.
You have two options. I assume your are going to a blank page, because your POST goes to a PHP script different from the page it is posting from.
Option 1 - Post to the same PHP page as the page your are posting from.
Option 2 - Once you have posted, and generate an error, redirect back to the page, with the errors stored in a session, or a cookie, so that they can be rendered on the original page.
Assuming that the page containing the request form is also able to display the error messages, set the form attribute to the url of the page containing the form (as TJHeuvel noted) or just make action attribute empty, e.g, <form action="">.
After going to blank page store all the posted variables in your variable say $get with syntax param1=value1¶m2=value2 and so on...and redirect back by header("Location: back.php?$get"); and in your main page by $_GET echo all the vars