Currently I'm building a plug-in for wordpress, where I have a couple of webpages with tables, filled with data from a database. Right now I'm working on the part where I click on a number (MemberID) which should redirect to a page, having all the information from another table regarding this number. I've tried transfering the data through the URL, with both
?MemberID=".$item->MemberID."
and
/MemberID="$item->MemberID."
, but everytime I try to alter the URL, the webpages suddenly can't seem to find itself anymore. I'm sure it has to do whith this part of the code:
add_submenu_page( null , 'Manage memberDetails' , 'memberDetails' , 'manage_options', 'memberDetails' , 'memberDetails_list' );
where the fifth value sets the URL for this page to be
http://localhost/wordpress/wp-admin/admin.php?page=memberDetails
So whenever I try to add something behind that URL, it doesn't acknowledge the existance of said page anymore, resulting in a redirection error.
Is there a way to transfer the variable without using the URL, or is there a way to give more of a dynamic to the URL?
You are using add_submenu_page wrong. The first param is required and can not be null.
https://codex.wordpress.org/Function_Reference/add_submenu_page
You need to get that fixed first so you page properly works.
As someone pointed my fairly basic mistake out this is what went wrong:
The URL is
http://localhost/wordpress/wp-admin/admin.php?page=memberDetails
where I tried to turn it into
http://localhost/wordpress/wp-admin/admin.php?page=memberDetails/memberID=
which creates a whole new webpage and is therefor impossible in this case. I need to transfer the variable behind the memberID=, not refer to a whole new webpage. The other thing I tried to do was
http://localhost/wordpress/wp-admin/admin.php?page=memberDetails?memberID=
which is impossible, because the second ? in the URL needed to be replaced with a &
From there on, it was pretty easy to use $_GET to retrieve the variable from the URL and use it.
So for extra clarity, this is how the URL is supposed to look
http://localhost/wordpress/wp-admin/admin.php?page=memberDetails&memberID=
Related
I'm trying to learn PHP, and to do so im trying to create a code to register new products, i've made an loggin access where the person to do so needs to be connected, so inside of the cpanel I did differents sections, like add client, add product...
So i did an index in the _cpanel folde where i have my main html and to not repeat the same html i put an include inside this index so i can call others php files inside.
I dont know if its correctly to do like this BUT, as i said Im new at programming..
But everything works pretty good, until i need to call my post in my url..
like.. to add a new product i need to go to :
localhost -> connect... to go to localhost/_cpanel
if i click in add a new produt, i go to localhost/_cpanel/?page=folder/addnewproduct.php
and inside this php file i put a form with an action="?go=addnewproduct"
so, i did everything to put all the info in my db, but when i submit it goes to
localhost/_cpanel/?go=addnewproduct and nothing happens..
i tried to change the action like action="folder/?page=addnewproduct.php&?go=addnewproduct" but it doesnt work either.
BUT i made it works changing to action"folder/addnewproduct.php?go=newproduct
but to do so i need to go to "addnewproduct.php", and this page only is an included page inside my index..
i could call back to the index page after adding a new product, so that it doesnt show this page only, but when posting it loads fast to the page and after than it go back to my _cpanel.
i tried to find solutions but, didnt find... i think its just a problem with the way i put it in my action, maybe theres a way to do it and i dont know it yet.
I don't think I get what you're wanting exactly, but here you go:
If you're trying to redirect the request, you may just use the header function as follows:
header('Location: target/url.php');
If you want to make a external post request with php, you may use curl, as suggested here:
PHP + curl, HTTP POST sample code?
Okay php newbie here, please bear with me. I am not sure if this is a redundant question but here goes. I have a reference code i want to stick to my url. example: site.com/index.php?refcode=123. That's fine right? we can put anything on there. Naturally the visitor goes to the index page. But if the visitor then clicks on other buttons that leads to other pages in my site, the parameter is gone. Like I want to track which code the visitor has when he sends me an email when he later decides to go to my contact page. How can this be done with php? or can this be done with jquery?
You would be best off saving the url variable into a session variable instead. The session variable will stick with the user so you have access to it no matter what page they go to.
$_SESSION['refcode'] = $_GET['refcode'];
Make sure to use session_start()
But if you do want to do it the way you have asked you can modify all urls on your page and add:
'?'.$_SERVER['QUERY_STRING']
This will add the query string to your url so the next page they go to would still have it. But that does seem like a lot more work.
OK - Thanks for taking the time!
I am using WP on a CentOS 6 server. I have a plug in with the functions, I have a function that makes a DB call and populates relevant products based on $_GET variables, I took from one of the other project and modify it so it works! But here where I run in to the problem, I go to the main page and i have a function that gets called first, goes through the URL name and determines the categories id and then from that I need to pass that to the URL so that when the next function then calls $_GET["category_id"] and that ID is there and ready to be use and it it does its magic. (all staying on the same page no refreshing or anything)
So I need to put that on the URL as the page is being loaded and so that I can use it (Again i get the variables from a function that is doing all the work with the address for relevant info,) So how do i do it? HTML or PHP, and a straight forward way no extra installs would be nice :)
Edit 1:
So is there something then I could integrate in that would be simple and straight forward that would allow me to do a mini refresh and get the right variables in place, never used JavaScript but seams to be getting or something in php ... Ideas are welcome :)
You can with javascript and the history API
The only way you can change the url without actually redirecting the user is by using the pushState method.
e.g. open a console and copy and paste this:
var stateObj = { foo: "bar" };
history.pushState(stateObj, "changes url to stackoverflow.com/yes-you-can", "/yes-you-can");
You won't be redirected, and the url of your browser will change unless, basically, you're using IE 9 or less. You can see a demo of this on html5demos.com
OK here is how I am going to get around this problem I am having
I made a new table in the DB and then I already have a list of the Domain We are using, so then I am going to give to the customer there are three columns and they will manually enter the fields and it will be on them to manage and change what they want displayed on the webpage.
CVS import and then BAM! done! just pull $_SERVER["SERVER_NAME"] and then compare that to the domain column and done! (I will have what ever cat's and sizes they want and it will not be on us to create any complicated functions and if statements for exceptions and it is in there hands!)
Not the exact answer I wanted to get but much easier and not so much complicated :)
On my website I use a pagination (similar to that one on the bottom of this page) for MySQL output. For the change of the current page I use GET method (variable page) and it works well.
However, on my page I have also a form, using method POST, which acts as a filter for the MySQL output. This rises a problem because, when I change the form settings an submit them (POST), the page in the address line (GET) remains the same. This is problem in some cases when the filtered output has less pages than that one currently set.
Is it somehow possible to set the page variable to 0 always when the form is submitted?
Particularly, I did it using $_SERVER['REQUEST_METHOD'] == 'POST'. However, this changes just the variable in the code. Not at the address line.
On the other hand I want to keep the POST variable when I change the page of the output.
Thanks in advance.
There is a logical collision in your setup:
Unlike GET method, POST method doesn't keep variables in the address bar. But for some reason you are using POST method.
So, the solution is quite simple - use GET method for the filtering.
To create pagination links use http_build_query() out of $_GET array
In fact it's better to send filter criteria in the address (GET method). It will solve your problem with pagination and you (and your users) will have a direct link to search results.
In your PHP code, you want to redirect to the URL with the page GET parameter removed if you are SUBMITTING (by pressing the "Filter" button, or whatever it's called). So it will start at page 0.
You would have to rewrite the URL yourself (or using a plugin).
Typo corrected, I meant page 0, not 1 :P
I didn't know how to ask professional so if topic is wrong, please correct it.
My problem is quite complicated. I was training on symfony webpage how to generate form and then send this data to another page.
But now i would like do something different. I would like create page xyzSuccess.php.
Then generate 29 links on this page. Each links would have its own number.
Each link would redirect to the same page. For example numberSuccess.php. After that, this site would give me data of the number which i clicked.
I will show the example :)
Page xyzSuccess.php have links, the third one is http://localhost:8080/web/number?nr=3
I click on it and i go to numberSuccess.php, the page give me number 3
After the page got number, also take from any datafile information under that number 3 ( i don't know, maybe any file wchich can store symfony / array somewhere?.)
I dont know how to do this, i don't want use any database eq. *sql
So far i created only page xyz.php which use php for loop. I see that action.class.php would work with it if i would use submit button, but i really dont have any idea how make this working with links. And... that problem with storing data :( maybe create file in lib/form ?
corrected the link to page (deleted success which used only in templates), guy under is right :)
First of all, you're talking about URL's like /web/numberSuccess... That probably means you've misconfigured the root. Also see this question, asked today.
Then it's common to give your actions names like number, and then in you're actions file you have the executeNumber action, which then renders the numberSuccess template. So you shouldn't include the Success in the action name/URL.
Then, your question:
What I would do, if you don't want to use a database:
Create a file links.txt in your /data directory, and on every line create an url, followed by a space and then the title of your link.
In your list action open the this file using file_get_contents(), explode it on the newline-character, and assign this array to the view.
In your view loop through the array, use the array index as your number, and explode each item on the first space, so you can display the title.
In the view action your open and explode the links file again, and now you can pointer directly to the index, explode again and you have the URL.