I want to get values of clicked links in the final page.
e.g. Computer & Network/Components and parts -- New York /City
Example.
Page1
$Category = $_POST["cat"];
$Subcategory =$_POST["Subcat"]
Page 2
$Province = $_POST["Province"];
$City =$_POST["City"]
{echo "You selected to post on"$Category . "Subcategory" In $Province . $City}
I want to use links not submit button to display selected links
USE $_GET
for example :
link
PHP:
echo "You selected to post on" . $_GET["cat"] . "/" . $_GET["subcat"] . " - " . $_GET["province"] . "/" . $_GET["city"];
Normally, this sort of thing is accomplished with $_GET variables, rather than $_POST variables. These go after the document name in the URL. Like so:
site.com/myPage.php?cat=Category&subcat=Subcategory
If you absolutely need POST (for reasons I'm not sure I'd understand) you may be able to use a Javascript framework like JQuery to make invisible forms that post when you click a link. Just realize this is going to make navigation hell...each time someone clicks 'Back', the browser will warn them they may be resubmitting information.
The easiest way would be to use COOKIES.
But I recommend using the get method to pass them via url, and that is described in the other answers here.
Example
Page1
$Category = $_POST["cat"];
$Subcategory =$_POST["Subcat"];
$_COOKIE["cat"] = $Category;
$_COOKIE["Subcat"] = $Subcategory;
Page 2
$Category = $_COOKIE["cat"];
$Subcategory =$_COOKIE["Subcat"];
$Province = $_POST["Province"];
$City =$_POST["City"];
echo "You selected to post on".$Category . "Subcategory In". $Province . $City;
Related
On my custom Single product page, I want to link every value of pa_ontwerper to the correct page. I used this code what works if pa_ontwerper has only 1 value:
$ont = $product->get_attribute('pa_ontwerper');
echo "<a href='https://www.website.nl/attribute" . $ont . "/'>" . $ont . "</a>" ;
This results in: designer1 with link to www.website.nl/attribute/designer1/
But when pa_ontwerper has for example 2 values, the output wil show something like:
designer1,designer2 with a link to www.website.nl/attribute/designer1,designer2/
Which is wrong.
What can I change in the code to make sure both values are linked correcly?
How do you place a $_GET['****']; into a string or make it into a variable.
For Example i have this url:
http://localhost/PhpProject2/product_page.php?rest_id=3/area=Enfield.
I want to get the area and rest_id from the url. in order to redirect another page to this exact page.
echo"<script>window.open('product_page.php?rest_id= 'put get here'/area='put get here'','_self')</script>";
I have so far done this:
if(isset($_GET['rest_id'])){
if(isset($_GET['rest_city'])){
$_GET['rest_id'] = $rest_id;
}
}
This obviously does not work, so my question is how do i make the 2 $_GET into a variable or call the $_GET into the re-direct string.
What i have tired so far
echo"<script>window.open('product_page.php?rest_id=' . $GET['rest_id'] . '/area='put get here'','_self')</script>";
How or what is the best practice?
ok, first things first. in your URL you have to separate the parameters using an ampersand "&", like this
http://localhost/PhpProject2/product_page.php?rest_id=3&area=Enfield
Also, you have to assign the $_GET value to a variable, not the other way around, like this
$rest_id = $_GET['rest_id'];
so if you create a PHP file named product_page.php and use the url i gave you, and your PHP code looks like this, it should work..
<?php
if (isset($_GET['rest_id'])){
$rest_id = $_GET['rest_id'];
}
if (isset($_GET['rest_id'])){
$area = $_GET['area'];
}
$url = 'other_page.php?rest_id=' . $rest_id . '&area=' . $area;
header("Location: $url");
?>
The question here is why do you want to redirect from this page to the other, and not send the parameters directly to the "other_page.php"????
I have a google map on this page, all markers were generated by submit postcodes. So I have the array below, loop info of each marker,
imploded as ("array", "array") format, I am trying to click on a infoWindow and display the according marker details on details.php.
The problem is everything is on the button onclick event, only a simple get on the second page.
This is working, but it is a very bad way. Because the limit to URL length and security reasons;
I would like to be able to get an array info from details.php page,
and the button onclick event trigger url looks like: details.php?marker=id
I don't know what is the best way to go about this, can someone pointing me to the right direction please?
index.php
$info = array();
foreach($stmt as $x)
{
$info[] =
"<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['Address']."<br />" .
"<h5>Postcode: " . $x['postcode'] ."</h5><br />" .
"<button onclick='window.location.href= \\\"details.php?marker=". "<h4>" . $x['name'] . "</h4><hr />".
"<h5>Address: </h5>" . $x['address']."<br />" . "<h5>Postcode: " . $x['postcode'] ."</h5><br />" . "\\\" ' >
View Details</button>";
}
$i=' "'.implode('","', $info).'"';
details.php
echo $infomarker = $_GET['marker'];
You have to use $x['id'] insted of $x['name'] which is unique in your database and also use base64_encode() for encryption of your id "details.php?marker=".base64_encode($x['id'])."
In your details.php
$infomarker = base64_decode($_GET['marker']);
Try using AJAX to get the info from details.php and then load it into your InfoWindow.
I didn't realise how simple this was, all I need is use that id, write it inside a sql statement in details page then call any part of the statement out. Thanks everyone. Thanks to #Manjeet Barnala for encode tips.
How to populate current page title (or current url) to the subject line via mailto?
Been using the code below as a starting point, obviously modifying the "Page Title Here" bit, but can't find a solution:
<?php echo "<a href='mailto:test#test.com" . $to . "?subject=Page Title Here" . $subject . "'>Send an email</a>";?>
Set page title to php var as
$title = 'Example';
and use it for
<title><?=$title;?></title>
and mail
<?php echo "<a href='mailto:test#test.com" . $to . "?subject=" . $title . $subject . "'>Send an email</a>";?>
This is not generically possible with PHP. PHP has no knowledge of what the page title is, or your HTML structure at all.
You will have to go to your code where you set the page title, and use that same variable in your e-mail. If this PHP code is handling a post from some page or something, you need that page title posted with your form data (which you can get with JavaScript document.title).
I have a standard HTML form on a WordPress post that the visitor will fill out. It consists of mostly checkboxes. What I would like, is after the form is submitted, a page is then presented to the user showing what they checked. For example, if the visitor checked off Checkbox A, B, and E, (but not C and D) then upon submission they would see the following:
You submitted:
Checkbox Value A
Checkbox Value B
Checkbox Value E
Obviously I can do this with just PHP, but my client would like to be able to modify the form options. Therefore I will need an easy to use backend.
Is there a plugin or user friendly way that this can be created? Or is my best bet to start building it myself?
the easiest way would be:
<pre>
<?php var_dump($_POST);?>
</pre>
but you can style it like:
<?php
foreach($_POST as $key=>$post_data){
echo "You posted:" . $key . " = " . $post_data . "<br>";
}
?>
Note that this might give errors if the $post_data type can't be displayed as a string, like an array in the POST data. This can be extended to:
<?php
foreach($_POST as $key=>$post_data){
if(is_array($post_data)){
echo "You posted:" . $key . " = " . print_r($post_data, true) . "<br>";
} else {
echo "You posted:" . $key . " = " . $post_data . "<br>";
}
}
?>
You can do something in jQuery.
$.post(
"post.php",
{checkbox : 1, checkbox2 : 0, checkbox3 : 0}, // this is the body of the post request
function(data) {
alert('page content: ' + data); // look up values in checkboxes and display them
}
);
Im not sure what kind of data wordpress needs, it might also need some session id to be sent if you need the user to be logged in.
If you wanna to show a json encoded list of the POST array is simple as
<?php echo json_encode($_POST);?>