I have a requirement, 2 php pages, one for entry purposes and another for display purposes.
Page 1- badgeentry.php allows an admin to enter badges numbers 123 and clicks submit.
Page 2 - badgedisplay.php allows all other users to view what the current badge number is. In this case 123. This page is using the "Refresh" meta html tag.
As far as the development, I have badgeentry and badgedisplay coded for. However, I want admins to stay on badgeentry after submit is clicked and still post data to badgedisplay. How can I do that?
Also, how do i maintain the badge number until the number is updated by admin. Currently, I lose the post value on badgedisplay page.
PS: I cannot use databases, maybe Javascript if I really have to
Thanks in advance.
With JavaScript: Use AJAX to post asynchronously in the background.
Without JavaScript: Post to a hidden iframe (with <form target="name-of-iframe">)
Related
The website I am working with is a property sales site where the user can freely advertise their property. Properties can be for sale or for rental: http://ev-villa.com
The search panel I designed has 2 tabs: For Sale and To Rent. To get a clearer understanding of the following problem I would advise you to load the site from the above URL. As the site is multi-lingual you may have to change the language to English by clicking on the flag icon in the top right of the page.
So the tabs in the search panel (left side of the page) can be clicked by the user and this tab will now change colour to show that it has been selected. This is handled by a variable in the URL called saleType. So if the value of this variable is equal to "torent" then the "To Rent" tab will change colour (The css on the page changes when the variable's value changes). Apart from changing colour this variable also affects the search results gained when the user clicks the search button.
The issue here is that the variable change is done by a link which requires reloading/redirecting. So if these tabs are clicked a few times, the result is that the user will have to click the browser's back button quite a few times to leave the website or to get to other parts of the website.
I am basically looking for an alternative solution to changing the value of this variable in php without using a link so that the value is set without redirecting the browser to a new page. I am trying to avoid the use of JavaScript and other languages, to ensure maximum cross-browser and cross platform compatibility, making sure this website works for browsers that don't support JavaScript or don;t have JavaScript enabled at the time of use.
I wasn't happy with my previous answer, so I gave it a little bit more thought.
Here's a workaround, completely without JavaScript and without requesting the server:
Instead of 1 form for both types of search (rent/sale), create two identical forms but with different action attributes.
<!-- Rental -->
<form action="search.php?saleType=torent" method="get">
...
<!-- Sale -->
<form action="search.ph?saleType=forsale" method="get">
...
Use CSS to position the forms on top of one another, and to hide one of the forms.
Use the Checkbox Hack to detect a click event on the form "For Sale" and "To Rent" links (you'll need to make them a <label>), and to hide/show the respective form.
I'm planning a site and I was thinking would it be possible to show alternate content in the sidebar based on the behaviour of the visitor? Say the user has clicked on link X on page A and I want the alternate content in the sidebar to be shown on page B, if they clicked on the link. Also, if the visitor fills out a form, would it be possible to associate the tracking cookie information with the submitted form to see what pages the visitor viewed? Would this be easier to implement in a particular cms?
I would appreciate it if someone could at least point me into the right direction. Thanks in advance!
Yes anything is possible & no need for cookies (unless you want to keep a persistent track of the user)
Have a relationship column next to the content in your db, when creating the content assign this value much like a category or tag ect.
Then when user clicks on link A as the page loads store its relationship in the session, then when link B is clicked load content related to the previous set session value.
The scenario (all happening within the administration area/backend):
From the listing page, the user clicks a link to view an article (on the backend).
From the article view page, the user clicks a link to edit that article.
In the article edit page, form is submitted to the current uri.
If validation succeeds or user cancels, user is redirected to the article view page.
From the article view page, the user click a 'back' link to return to the listing page.
List <--> View <--> Edit
Right now, I'm only able to track referring url from a previous page. In the edit form, I'm using a hidden field to maintain referral to the view page, lest it be changed during failed form POST submission to itself and user remains in the edit page.
Problem is that when the user returns to the view page from edit, the 'back' link to the listing page is now linked to the edit page.
FYI,
The listing page url is dynamic as the user should return to the listing on the same page and sort order (stored in query strings); therefore a fixed url is out of the question.
In the past, I've tried using sessions (e.g. SESSION['view_to_list_ref'] SESSION['edit_to_view_ref']), but it messed up with multiple tabs.
I could transition between view/edit via ajax, but I'm hoping to keep the app simple and ajaxless at this point of time.
I'm using PHP + Kohana 3.2 Framework
The only solution I can think of is to have the list page url encoded and appended to the 'view article' link via query string. This way, the location of the listing page is preserved even while in the edit page; as the referring url back to view page would also contain the listing page url in the query string. However I don't really like the idea of 'dirtying' the url with long parameter values (encoded or not).
I'm really hoping there is a more elegant solution to this problem of generally tracking multiple levels of page referrals; not just specifically to solving the scenario I've mentioned.
EDIT: Oh and the solution should be able to support multiple tabs performing the same scenario.
You could track the pages by using a unique identifying code in a PHP session, a temporary variable, and using a temporary database table that tracks page loads by these temporary values.
The database structure might be:
+-------------+-------------------+---------------------+
| Unique ID | Page Referral | Time of page load |
+-------------+-------------------+---------------------+
Tracking time of page load would allow you to selectively wipe loads older than X minutes, and keep the table relatively small.
Anyway, this would allow you to keep as many levels as you'd like, and if you wanted to add an auto incrementing counter field, or your own counter field, you could even keep a simple to use number system that tracks page loads, though I believe the time of page load would suffice for that scenario.
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 run a php script game site, and there's a section of it where a player can distribute his 'skill points' in 'Attack', 'Defence', or 'Stamina'.
At the moment, it's just a basic HTML/PHP form with a + next to each stat, so if the user had 100 points and wanted to put them all into ATTACK, he'd have to click (and pageload) 100 times. Obviously that's silly.
I want to be able to make it so the player can distribute them (without page reloads), then finally click SUBMIT once he's happy with it.
Could anyone point me in the direction of what I need to do this? Is it some ajax or javascript? I suppose I could do form fields and clicking the PLUS would increment each field..
It sounds like you need an onclick() to call a javascript function for the plus button, that increments the value in javascript, updates on the page and checks that the user has distributed the points correctly (i.e. distributed 100 points or under in your example) and then have another button at the bottom of your points distribution that sends the data to a PHP page that handles the storage of the values.
If you wanted you could then use ajax to send that data to the PHP page without having to reload the page. I've found the W3schools site adequate for teaching basic ajax usage: http://www.w3schools.com/ajax/default.asp
(But remember to check the user input on the server side as well, don't trust user input!)