Say I wanted to create a popup for my website that only showed once (if the user either filled it out or clicked the "do not display again" button), how would I do so. I am creating the popup and form using javascript and html, passing it in php to a database.
The easiest way would be to use a cookie which would be downloaded to the client's computer. When your webpage loaded, it would need to check for this cookie, and if not found, or a flag inside it had a property "noPopup=true" for instance, not display the popup.
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.
How can I use php to echo a page instead of linking to existing html page with hyperlink?
One example would be
<html>
<body>
click on this link to go back
</body>
</html>
Now, I don't want this link above to be a link to html page but to echo a page with php code when user clicks on click on this link to go back(to generate a page). This way, nobody can access a page after they logout.
Can php do this?
If someone logged out of your website or application I assume you will have a check whether or not this person is allowed to view the content.
Your question itself is very unclear to me. But it sound a bit if you want to do client-side coding (don't follow a link when it's clicked) with PHP which is not possible since PHP is a server side language. You will need Javascript to change the behavior of a link (for example, make an AJAX request which returns the content of another page).
Create a function, what the function should do is it should get triggered on a button click event and the code inside the function must send an curl request to the url you want and get back the html from it and echo it on your page
For answering the second part of your question!. you want no one to access the data without logging in so maintain $_SERVER['']; and sessions for users and validate if the user is inside a genuine session then show him content else no
I'm trying to find a way for PHP to press the "submit" button on a PHP form on a live webpage.
I need to do this as I am unsure as towards what data is send through this form, as it is a post form and the API is closed source.
Is there anyway to send a jQuery like click command to a live webpage through PHP at all?
Nothing needs to be retrieved from this form, only needs to have pressed the button correctly.
EDIT
More context:
Yes, the site is 3rd party (this is why I can't simply look up something on any API documentation), the program is downloading a gallery of images through the in-site gallery archiver. Previously the URL for this gallery's archive was stored on a simple popup window page's source. Now however you must confirm it first the page reloads (after a form submits through POST) onto the same page (archiver.php) and the download starts. This reloaded page contains the URL of the file. Nothing is submitted beyond the users confirmation to the download manually, perhaps something in the back end is sent upon this, I don't know.
EDIT 2
I've fixed this by figuring out what the form submits.
I think it is not possible to click a button on another page with php or jquery.
But you can analyse the form and find out the destination URL and send a own request. If it is GET it should look like this: myhomepage.com?id=1&name=foo&password=hello123
you have to use jQuery or javaScript For pressing submit button on live page dynamically. PHP is server side script and from is client side so its not possible. but if you want to read data from live webpage than you have to use cURL or file_get content
I want something like when you click on image on facebook, url changes to facebook.com/photo.php?.... but without redirect. I want exactly the same thing but to open the messages, not photos. Simply, i want when user clicks on displayed messages with other users to open a new popup window without redirecting to new page with all messages with that user. Is that possible and if it is please tell me how to do that.
Example:
Messages with user A
Messages with user B
Messages with user C
And when user clicks on 'Messages with user B', it will open new popup window with all messages with that user, and of course, pulled from database.
I decided to write this as an answer since it is too long for a comment.
To "properly" set up what you want, you need several parts working together:
AJAX: (eg: jQuery.ajax) Retrieve data from the server programmatically with javascript
CSS/HTML dialog: (eg: jQueryUI dialog) Create a fake popup inside your page, usually to give the content some prominence
History State: (eg: SO Q/A) Change the page URL (in addressbar) without reloading the page.
I think I understand what you are looking for!
Use case scenario:
1- User looks at a feed of posts/images/anything.
2- User clicks on one of those posts and, it opens in a box with that same content.
The thing you are looking for is called "Lightbox" or "FancyBox".
I googled and found a few examples:
http://fancyapps.com/fancybox/
http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/
http://lokeshdhakar.com/projects/lightbox/
you basically need to recreate the loop or make on a onclick function when user chooses the photo, and just call the index of that photo again inside the lightbox.
I'm using PHP CodeIgniter with jQuery.
Say for example I have a <table> (of employees perhaps).
Now above the said table I have an "Add Employee" button.
This button opens a jQuery-dialog with the <form>. When this form submits, it goes server-side of course (validates whether a duplicate entry or not), then it's sent back to corresponding view with the updated table.
What I want to do is to show a dialog that an employee is successfully added or that it is a duplicate entry.
I'm doing this by
appname/controller/action?addSuccess=true
or
appname/controller/action?addSuccess=false
everytime I return back to the view, then on my page, in my $(document).ready() I check for such query string and opens the corresponding dialog (success or error dialog). My problem now is that, if I refresh the page (same url) I get the dialogs again (although nothing happens serverside).
QUESTION: Is this approach good enough? Any good advice to improve this? :)
Thanks a lot!.
Instead of passing that info as a query parameter, why not store that info Code Igniters flash data. This data gets persisted across only one redirect. The next time you reload the page, the data will not be set (as CI will automatically remove it for you) and you wouldnt accidentally display the warning.
Form is submitted to server. Set appropriate value in CI's flash message system.
Redirect to another url? Or maybe display another view.
In the view html, use php to read that flash message value and set an appropriate value in javascript.
Read that js value and accordingly display the popup/modal/message.
The flash message data will be removed automatically by CI at next page refresh.
Some sample code meant for the redirected view html: (I dont do php...)
var shouldDisplayWarning = "<? php code that sets some value based on flash variable ?>";
if (shouldDisplayWarning === "yes") {
displayWarning();
}
Further reading: http://codeigniter.com/user_guide/libraries/sessions.html (half way down the page they mention flash data.)