I have a form with many inputs, but not all inputs must be filled in.
Form action is set to a php file, which checks which inputs are set and builds a query to query MySQL.
Then I display the results on the main page, and the users may click on an ad to show.
When clicked an ad, a new page opens with several options for the user (change ad, delete ad, save ad etc).
On this page, I am currently struggling with a 'back to search results' button/link. I don't know how to do this. I thought firstly about the 'history.go' to just make a 'back' button, but if the users would use one of the options on the page then the 'back' wouldn't work!
Another way would be to somehow save the query in a hidden input and pass it to the 'show ad' page or something... But this seems unsafe as the query is visible to users!
Do you have any ideas or suggestions?
Thanks
Save the data you need to build the query in the page. This could be a copy of the original form with all the input types converted to hidden.
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 have a page. At the top there is a search box, that user can select search options in it. Search form will be submitted via GET method.
At the bottom there is another form, containing a collection of embedded forms, with one save button for all of embedded forms that submits them by POST method.
When I select search options and submit the search form, I can get the search form with selected searched options showing up by default, and the result form with search results in it.
When I submit the form of results by clicking save button, the previous selected search options don't show up by default in my search form.
So my problem is, I don't want user select search options after each save action... I want them to show up by default... So I understand that when user clicks Save button, it just submits the bottom form via POST method, and that's the reason I don't have search options there.
I've tried to store query() parameters from the search form and keep them in a session parameter, but I don't know how to pass this parameters to the search form, should I inject them in the request?!
Isn't there any sane approach to make 2 separate forms collaborate with each other in symfony2?!
Thanks in advance for your time! I appreciate any help or suggestion! Thanks!
so I figured out that even when I submit the form in the bottom that submits the form by POST method, I still can reach the other form parameters using: $request->query->all()
Kinda cool, I got the reason why it couldn't work before, because I was redirecting to page by appending parameters from $request->query->get('search_form') to the url, and it was empty...
Ive got a member search form that searches users on my site. The form method is get.
The results are displayed using Ajax on the same page. The page is not reloaded.
If a user clicks on a search result, then the appropriate page is opened in the same tab.
The problem comes when a user clicks back. Because the search result has opened in the same tab, clicking back returns you to the page with the search form, but all search results are lost. The user therefore has to start the search again.
The only solution i can think of is to not use ajax and post the search terms to the url. But thats not ideal.
Anyone got any better solutions - somehow storing the get variable so that ajax can pick it up again?
I think you used 'history.back()' for back button. You should use get or post to pass inputed variable of user to form search.
I need store different post data to each tab in a browser. If I open a new instance of the same page, the data aren't shared between both.
My problem:
I'm building a CMS to control my website content. But I will open some instances of the same page (many tabs). So I have a search form to find news that I been created on my CMS. If I open a news item I have a cancel button that back to previous page (the news list).
The problem is that the news list have a pagination and a filter form. So I can, for instance, search by a term like "john doe" and advance to page 5, and open a news item. If I cancel, currently I back to news list without filter and on first page.
My solutions:
Well, I don't want to use the history.back() because I can submit a news form and click on back/cancel button. So, I'll back to the current form, what is wrong.
My second idea is to store a $_SESSION with the $_POST sent to the news list and the back button send me to /news/list/recovery-session, that will recovery the $_POST data from session. But it have a problem: if I open two tabs and make two searchs, I'll have only the last session saved.
Your solutions:
Well, I can work with PHP and JS to make it work. You can suggest a idea of what I can do. I think about work with COOKIES, but I belive that it is shared by domain, and not by tab, what is a problem.
Someone?
Generate a unique id and attach it to the form or some hidden element that will be submitted. Save that unique id in a cookie or session variable. Compare the two at time of submission.
If second tab has generated a new id, the first tab will not evaluate to true.
The main problem is the need to persist the state of what page to return to and also the search term when returning back to the news list page. There are many ways to accomplish this, but one simple method is by encoding this data into your query string.
As an example, assuming your search term is "john doe" and you are on page 5, pass that data along to your news page.
news.php?returnSearchTerm=john+doe&returnPage=5& ....
When the news page is created, you can format your cancel link to send you back to the list page with the correct parameters.
news_list.php?search=john+doe&page=5
I have a page with two forms that is generated with PHP.
The first part contains text boxes, a submit button and a clear button.
The second form is just a button called "Add more text boxes" so the user can add more to his form if he needs to.
The problem is when I click the "Add more rows" which loads another page which changes a value.
This value then affects the original page when it reloads causing more text boxes to get created.
The problem is that I lose all the data that was entered.
Is there any way to preserve the data when the user clicks "Add more rows"?.
Here's a screenshot of my page.
Thanks
If you want to do it without js than you put all in one form. When you click button to add row all entered data will be available in $_POST or $_GET so you can fill form with existing data and add a row when generating new page.
Ideally you should use javascript to dynamically add new rows w/out making new requests to the server and loading new pages. But if you want to keep it javascript free. If it's all the same php script just controlled by conditions, just use the $_POST['variable'] values as the value="$_POST['variable']" in your fields. If it's handled through multiple scripts, you can use a session variable to pass the data from one page to the next.