How to disable Script on certain selected page - php

1st of all, its not Wordpress. Just PHP and HTML.
Is there any way to disable a few script on selected pages? I've saved all my custom script codes on scripts.js and serving it to all the pages in my site.
What I'm facing is conflicting issue. i.e. Login js code is having some issue with search js code.
I've searched all over the net but unable to find a solution. All I'm getting is for Wordpress with wp_enqueue. Is there any way to something like that? I mean disabling some script on selected pages?
jquery codes: http://pastebin.com/63eGKkCc

Its common problem if are using duplicate ids in different scripts.
For egs, if you are using name as id in login script and the same id is used in search script, so definately these 2 would create conflits with the same id name
Now, to reslove this you can have 2 options
Add unique ids to elements or access by using its parent selector like $('#parent_unique_id #name')
Add login script only to login page and search script to search page.
Updated, if you want to check the page and then add/run script then you can use location.href like,
if(location.href.indexOf('login')!==-1) { // for example its login.php page
// code for login page
}
And do something like for search page.

Related

Open newly created webpage in php

I want to create a new webpage using php. Then after I create the page I would like to open the page in a browser. I have the create part (create file) down and the delete file, but how do I (can I?) open the webpage from my php created page that has confirmation message?
To clarify, I have created an html page that asks the user to enter information to create a web page. I ask the name of the webpage, extension type, and a text box for content. I then give them 3 buttons - Create page, view page, delete page. If the user selects Create, I then run a php page that creates the file for the webpage and displays a message that the web page was created.
So, my question is how do I either return to the html page to allow the user to select view webpage(which does not require php) or to allow the user to select to view the webpage from the "Confirmation" page which is php?
Thanks,
Jason
You can alter the header file to do this, and some people may suggest this, but I've found that this causes issues without knowing more code that's been written before or afterwards.
I recommend that you use JavaScript to change the location of the page and simply place an "onclick" or "onsubmit" call to the below function on the button that creates the page.
<script>
function createAndRedirect(){
var x = document.getElementById("#idOfInputWhereWebPageIsSet");
var y = x.value;
// You can add an alter confirmation message here.
// alert("Web Page Created!"); Remove the comment slashes for a basic confirmation alert.
location.replace(y);
}
</script>

PHP MVC Append URL parameters without page reload?

I am working on a site which has an animated background, the animation is powered by javascript and therefore when the user enters and submits a search it would be great if the animation were to continue smoothly whist the search was completed and results appended to the DOM.
I have managed to get to the point where the results of the search are returned to JS from an ajax request although inherently the url of the ajax request is different from the url currently displayed in browser.
So my goal is for the user to come onto the site at say, www.example.com/public/home/search
They type something into text input and press search, the url changes to something like
www.example.com/public/home/search?q=some+search+query or
www.example.com/public/home/search/somesearchquery or
www.example.com/public/home/search/#somesearchquery, etc.
but the page state remains the same, the results are appended to the DOM and no full reload occurs.
Returning to a url like the one above should load the page and send the query automatically, returning the page with the results already appended.
I don't know weather this is possible, with or without obeying the MVC pattern.
I am not using any mvc framework and would like to avoid it if I can but instead using a bare bones system similar to the one found at. https://www.youtube.com/watch?v=OsCTzGASImQ
Any ideas, suggestions, alternatives?
There are several answers here for "change URL without reload", for example: Modify the URL without reloading the page .
So, I think you just have to implement some solution from one of these answers and run some javascript that change the page.
You have to be careful, because the modified URL must to load the same version of the page the user is seeing after the changes caused by the javascript. Otherwise, if the user copy and paste the URL, he will not be happy.
One way to archive it is to create the javascript function that "updates" the page without reload it based on the text input (let's say, f). Then, if the user try to access directly the page
www.example.com/public/home/search?q=some+search+query
your server side code just return the page search with a call to this javascript function at the end, like that:
f("some search query")
so, this function will update the page and the final effect will be the same as the user just enter in the page and after tries to type some search query.
(Note that, this function f may be used in both cases: when users type the text to search and when users just paste the entirely URL).

Sending information across pages PHP

i have an ajax / php feature of my site that pulls in information from a table every 20 seconds. The information is about hobbie's
It displays on the page the name of the person and their hobby. I have a second page that acts as an information source for that hobby. Currently the only way to access the second page is by entering your hobby into a form on the first page. How would i get it so that i could click on the hobby that is being displayed on the homepage and access an information page on the hobby.
To access the information it currently grabs the hobby from a POST command.
The table results are being displayed on the homepage via
echo $row['name']." is interested in ".$row['hobby'];
Could i some how pass the hobby name through to another page? I only know how to do it through form submits.
I don't think that sesssions are necessary for this.
Look at what information your form is sending. If you're making a GET request you can add that url to a link.
So on your home page you could have links like the one below instead of forms.
<a href="/hobbies/?name=remote+controlled+cars>Remote Controlled Cars</a>
So with the link it would no longer be using $_POST but $_GET instead.
Psudeo code for your homepage link below.
<a href="/hobbies/?name=<?php echo slugify($row['hobby']); ?>><?php echo $row['hobby']; ?></a>
Look into using PHP's sessions.
You can create an anchor tag that is generated from the data provided with a query tailing it to carry the data over, effectively creating a link pointing to the next step with additional information. The only problem, of course, is that this is exposed to the user which can be hijacked.
You can also, if you are using only form submits, create a <input type="hidden"> with a value/name of something you can use to navigate to the next page, if you so desire.

php, jquery pagination, storing current page

i'm having a shop system which is displaying articles using a jquery slider plugin, so there's pagination.
i'm having an item with record id 123 on "page" 3 - that item has a unique modrewrite url like www.domain.com/myitem-123.html
the problem: when displaying the article details i need to somehow store the current page of the slider plugin in order to jump back to the last page of the slider.
i wouldn't like to modify my modrewrite url as it wouldn't be unique anymore (there would be different urls for same item) - the only idea i'm having is using a php session, but i'd need to set it via ajax command on each click which doesn't seem very elegant to me ..
any suggestions?
I believe a better and easier approach is to simply store that page number in a cookie and retrieve it on the slider/listing page.
But if you want to get on with your idea and need an improvement, I'd suggest to store the page number in a global variable in JavaScript and only make that request to the server right before the user jumps to the product's page ( you actually have to do it synchronously since the user is closing the page and the request can't "sit" in the background )
window.onbeforeunload = function() {
// do your server request here to store the $_SESSION['slider_page_no']
}

Update Database record using jQuery/PHP and a link and not a button

I am attempting to make a registration-like page for a small forum. To register for an event, I simply want the users to click a 'link'. (It doesn't have to be a link, but I don't want it to look like a button, so fancy CSS is acceptable).
On this page there will be a limited number of openings per event. (Simple database query to populate this list). The users will then select one of the openings by clicking on it. At this point, I'd like that opening to close and the page NOT to reload (just the Div that link is in).
I know PHP/MySQL very well. Actually, DOING the insertion of the data is easy. What I don't know how to do is the clicking the link and not reloading the entire page but still showing that opening is now closed.
I've looked at jQuery. It seems to have the ability to do the autoreload. Can anyone help me out?
The insert in the DB will be the user's forum name (they are logged into the forum, I have access to that variable within my script). That is all that will get inserted into the database.
Look at the Ajax methods. To update the database you probably must do a $.post. Something like this will work:
$("#myButtonId").click(function() {
$.post(serverurl, $("myformId").serialize(), function() {
// This will be called when the post is complete
$("#mydivId").html('update html here');
});
});

Categories