I use the code below for simple search and it works well in index.php but because i added the code in header.html for include in all pages and the code result work only in index.php.
https://stackoverflow.com/a/34131517/5227465
index.php?text=keyword = ok
otherpage.php?text=keyword = here not work because search Processing only in index.php
I think the problem in this element means the current page that contains the code:
(document.getElementById)
<form id = "your_form" onsubmit="yourFunction()">
<input type="text" name="keywords">
<input type="submit" value="Search">
</form>
function yourFunction(){
var action_src = "http://localhost/test/" + document.getElementsByName("keywords")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}
any help?
I didnt test it but try this:
function yourFunction(){
var action_src = "http://localhost/test/<?php echo basename(__FILE__, ''); ?>" + document.getElementsByName("keywords")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}
Related
I have written the following code in custom.php file (just one file!):
jQuery(function ($) {
$('.price_calc').hide();
$('.lengthm2, .widthm2').keyup(function(){
var priceProduct = <?php echo $priceProduct; ?>;
var lengthM2 = $("#lengthM2").val();
var widthM2 = $("#widthM2").val();
var totalM2 = (lengthM2 / 100) * (widthM2 / 100);
var totalPrice = totalM2 * priceProduct;
$(".m2_customer_total").html(totalM2.toFixed(2));
$(".price_customer_total").html('€'+ totalPrice.toFixed(2));
console.log(lengthM2);
console.log(widthM2);
});
Now in the same file I have added the following code:
<?php
$lengthM2 = $_POST['length'];
$widthM2 = $_POST['width'];
echo do_shortcode( '[gravityform id="2" title="false" field_values="lengthM2='.$lengthM2.'&widthM2='.$widthM2.'"]' )
?>
I can't use the POST variables as I did not post anything.
But how can I manage this works correctly? I tried $.post (jQuery) which not works at all.
I have created a script that will work as a plugin for Wordpress whose purpose is to get the data of the videos of a page (video title, video url, thumb url and total videos found).
My plugin works but the script is on the same page where the results are loaded so that it stays in Wordpress. But I want to externalize the script in charge of doing the search because I sincerely do not want them to be able to visualize my php source code.
So I tried to separate my script and just put the html and invoke the script using the "action" form.
But I do not know how to pass the loops of my external script to the local form nor how to pass the values of the variables. I tried to use the "return" and "Header Location" but it does not work.
Here is what I currently have:
Index.php:
<?php
if (isset($_POST['search'])){
$url = $_POST['keyword'];
$parse = "http://example1.com/?k=".$url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
include("form_results_footer.php"); // I include the header of the page with the results (this part is outside the loop because I do not want it to be repeated).
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$counter++;
$title = //something value;
$linkvideo = //something value;
$thumburl = //something value;
include("form_results.php"); //The results of the "foreach" insert them into a separate php in "fieldsets".
}
$totalvideos = $counter;
include("form_results_footer.php"); //Close the form results
} else {
?>
<html>
<form action="" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
<?php
}
?>
Ok, the code above works fine but I need to outsource the part where I get the variables of the part where I will receive them, something like this:
-> http://example.com/script.php
<?php
if (isset($_POST['search'])){
$url = $_POST['keyword'];
$parse = "http://example.com/?k=".$url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$counter++;
$title = //something value;
$linkvideo = //something value;
$thumburl = //something value;
}
$totalvideos = $counter;
return $title;
return $linkvideo;
return $thumburl
}
?>
index.php
<html>
<form action="http://example.com/script.php" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
The loop results would have to be collected on the same page in the same way as in the initial example.
I hope you let me understand, thank you in advance.
Change form action url to self page in index.php and do cURL there which calls your another domain where logic is placed. that mean http://example.com/script.php
index.php
<html>
<form action="" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
<?php
if (isset($_POST['search'])) {
//your URL
$url = "http://example.com/script.php?keyword=" . $_POST['keyword'];
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $url);
// Execute
$result = curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
}
?>
And in http://example.com/script.php you just need to change $_POST['keyword'] to $_GET['keyword'] and few more change to return data.
scrip.php (from another domain)
<?php
if (isset($_GET['keyword'])) {
$url = $_GET['keyword'];
$parse = "http://example.com/?k=" . $url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
$return = array(); //initialize return array
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$return['video_data'][$counter]['title'] = //something value;
$return['video_data'][$counter]['linkvideo'] = //something value;
$return['video_data'][$counter]['thumburl'] = //something value;
$counter++;
}
$return['total_video'] = $counter;
echo json_encode($return); //return data
}
?>
I hope this is what you want.
i want the value of $code variable to get on my other page--- captcha.php.
captcha_image.php
$captcha = new CaptchaCode(); //class defined in captcha_code.php
$code = str_encrypt($captcha->generateCode(6)); //function defined in captcha_code.php
$captcha1 = new CaptchaImages();
$captcha1-> GenerateImage($width,$height,str_decrypt($code));
captcha.php
<img style="cursor: pointer;width: 50px;height: 50px;" src="refresh.png" onclick="refresh_captcha();"/>
<input type="hidden" name="security_check" value="<?php echo $code; ?>"> // want value of $code here
<script type="text/javascript">
function refresh_captcha()
{
var img = document.getElementById('captcha_img');
img.src = 'captcha_images.php';
jQuery("#captcha_img").attr("src",img.src);
}
</script>
I cant include captcha_images.php file in my code and even dont want it to be done using sessions, tried that way.If anyone has a solution for this, please help me to solve this issue.
Better solution is save code into SESSION.
For example:
captcha_image.php:
session_start();
$captcha = new CaptchaCode();
$code = $captcha->generateCode(6);
$captcha1 = new CaptchaImages();
$captcha1-> GenerateImage($width,$height,$code);
$_SESSION["captchacode"] = $code;
And check correctness after submit of the form:
session_start();
...
if($_SESSION["captchacode"]!=$_POST["security_check"]){
echo "Wrong captcha!";
}else{
// captcha is correct, process the form
}
If you cannot use cookies and session, you cannot get information from captcha_image.php which returns only image. You must generate information in else request, for example:
<img id="captcha_img" src="captcha_images.php?encoded_code=<?php echo $code ?>" onclick="refresh_captcha();"/>
<input type="hidden" id="captcha_hidden" name="security_check" value="<?php echo $code ?>">
<script type="text/javascript">
function refresh_captcha()
{
// generate_captcha.php returns only encoded captcha
$.get('generate_captcha.php', function(encoded_code) {
$('#captcha_hidden').val(encoded_code);
$('#captcha_img').attr("src","captcha_images.php?encoded_code="+encoded_code);
});
}
</script>
Here generate_captcha.php returns encoded captcha, captcha_images.php doesnt generate code, only decode code from hims parameter encoded_code and this code is also inserted into hidden.
index.php
<head>
<script>
function getpage(pageName) {
var obj = new ActiveXObject("msxml2.xmlhttp");
obj.open("GET", pageName);
obj.send('A=1&B=2&C=3');
var txt = obj.responseText;
myText.value += txt;
}
</script>
</head>
<body>
<input type="text" id="myText"/>
<input type="button" onclick='getpage("http://localhost/Last/callPageForIE/info.php")';/>
</body>
</html>
info.php
<?php
$A = $_GET['A'];
$B = $_GET['B'];
$C = $_GET['C'];
$sum = $A + $B + $C;
echo "your sumuatsdion is ".$sum;
?>
tried to get the result from info.php but it always give me zero I don't know why, can someone tell me where is my wrong?
You are passing your data as the request body. This is what you do for POST requests, not GET requests. GET request data needs to be encoded in a query string in the URL.
obj.open("GET", pageName + '?A=1&B=2&C=3');
obj.send();
PHP is then casting the undefined variables to 0.
You are also using the obsolete, Microsoft only, ActiveX implementation of XHR. You should switch to the standard, cross-browser implementation instead.
I have a site in html and in a page, I have buttons to take the visitors to dj's profiles.
Each button takes the visitor to a different dj profile.
I create a page in html that goes to a XML document to get the information of the dj. So, my question is, how can i add at the link of php page, the name of dj, so he can stay with a personal link?
I tried the get properties but i need to have the post too, in order for PHP to take the information of that dj.
The html of djspace.html page have this:
<form name="form" id="form" method="post" action="allProfiles.php">
<input type="submit" name="dj_name" value="Blowdrop"/>
</form>
...
<form name="form" id="form" method="post" action="allProfiles.php">
<input type="submit" name="dj_name" value="Psychokiller"/>
</form>
and then my allprofiles.php page:
<?php
$counter = 0;
$dj_name = ($_POST['dj_name']);
$xml = simplexml_load_file("Profiles.xml");
foreach ($xml as $newprofile){
if($xml->newprofile[$counter]->Anome == $dj_name){
$Anome = $xml->newprofile[$counter]->Anome;
$nacionalidade = $xml->newprofile[$counter]->nacionalidade;
$naturalidade = $xml->newprofile[$counter]->naturalidade;
$residencia = $xml->newprofile[$counter]->residencia;
$emprego = $xml->newprofile[$counter]->emprego;
$generos = $xml->newprofile[$counter]->generos;
$disponibilidade = $xml->newprofile[$counter]->disponibilidade;
$partilha = $xml->newprofile[$counter]->partilha;
$sitios = $xml->newprofile[$counter]->sitios;
$tempo = $xml->newprofile[$counter]->tempo;
$editora = $xml->newprofile[$counter]->editora;
$promotora = $xml->newprofile[$counter]->promotora;
$influencias = $xml->newprofile[$counter]->influencias;
$fblink = $xml->newprofile[$counter]->fb;
$scloud = $xml->newprofile[$counter]->scloud;
$mail = $xml->newprofile[$counter]->email;
$img = $xml->newprofile[$counter]->foto;
}
$counter = $counter + 1;
}
?>
I can get all the information but I if i apply the get, I can't.
Obviously if you go directly to php page, you get none information.
http://roundhillevents.com/allProfiles.php
However go in this link, and then, dj's, dj space, and then click in the one you want to see the information.
As #Marc B suggested, use link instead of form with button.
If you want to keep using buttons for whatever reason, change method="post" to method="get". Then browser adds the dj reference to the URL of the page for you.
Of couse, you then need to use $_GET['dj_name']) instead of $_POST['dj_name'] in your PHP code. This is for both cases, buttons with GET method and links.
this is because you are using $_POST in php. try using $_REQUEST or $_GET global variable instead of $_POST
try this
<?php
$counter = 0;
$dj_name = ($_REQUEST['dj_name']);
$xml = simplexml_load_file("Profiles.xml");
foreach ($xml as $newprofile){
if($xml->newprofile[$counter]->Anome == $dj_name){
$Anome = $xml->newprofile[$counter]->Anome;
$nacionalidade = $xml->newprofile[$counter]->nacionalidade;
$naturalidade = $xml->newprofile[$counter]->naturalidade;
$residencia = $xml->newprofile[$counter]->residencia;
$emprego = $xml->newprofile[$counter]->emprego;
$generos = $xml->newprofile[$counter]->generos;
$disponibilidade = $xml->newprofile[$counter]->disponibilidade;
$partilha = $xml->newprofile[$counter]->partilha;
$sitios = $xml->newprofile[$counter]->sitios;
$tempo = $xml->newprofile[$counter]->tempo;
$editora = $xml->newprofile[$counter]->editora;
$promotora = $xml->newprofile[$counter]->promotora;
$influencias = $xml->newprofile[$counter]->influencias;
$fblink = $xml->newprofile[$counter]->fb;
$scloud = $xml->newprofile[$counter]->scloud;
$mail = $xml->newprofile[$counter]->email;
$img = $xml->newprofile[$counter]->foto;
}
$counter = $counter + 1;
}
?>