I am trying to integrate two pieces of code together. The existing code already generates a hash code and the function is called with this URL
header(Location: http://".$_SERVER['HTTP_HOST']."/subfolder/controller.php?document&validate&patient_id=".$pid."&document_id=".$nid."&process=true");
Is there another way to execute this function without doing a header redirect because the header redirect is causing the code to halt processing upon redirect.
In the controller file there is only one line echo Controller::act($_GET);
I tried to convert it to a function. I tried.
include_once controller.php //class file
function hash_tag($pid, $nid){
$filetag = "document&validate&patient_id=".$pid."&document_id=".$nid."&process=true";
echo Controller::act($filetag);
}
hashtag($pid, $nid);
Any help would be greatly appreciated.
Code for the Controller.class.php file can be seen here
https://github.com/juggernautsei/Drag-N-Drop/blob/master/library/classes/Controller.class.php
You didn't post your code inside controller.php but considering that your first approach was accessing that code via url parameters, I'll assume that you are executing variables in that code as GET variables (example: $_GET['patient_id']).
If that is the case, now that you are executing that code via include_once you have to change the way you set your variables in controller.php because there is not more $_GET.
You are trying to pass the string from the GET request to the controller.
But Contract::act() works on an array ($_GET is a superglobal array).
Build an array inside the function and assign the parameters of the function to it, then pass it to the controller, like so:
include_once 'controller.php';
function hash_tag($pid, $nid)
{
$array = array();
$array['document'] = 1;
$array['validate'] = 1;
$array['patient_id'] = $pid:
$array['document_id'] = $nid;
$array['process'] = 1;
echo Controller::act($array);
}
hashtag($pid, $nid);
Related
I am trying to pass a variable that I receive in an ajax call to an add_filter function.
Here is my code
add_action('wp_ajax_mht_set_partial_payment_amount', 'mht_set_partial_payment_amount');
add_action('wp_ajax_nopriv_mht_set_partial_payment_amount', 'mht_set_partial_payment_amount');
function mht_set_partial_payment_amount(){
$amount = $_POST["partial_payment_amount"];
add_filter('woo_wallet_partial_payment_amount', function($partial_payment){
return $amount;
}, 10, 1);
echo json_encode($amount);
die();
}
The $amount is completely okay in the response but it is not working at all in the filter.
I have tried many other ways to pass the $amount variable to the filter(using a class or a global variable) but nothing works.
The ajax call simply takes an input field value. And I need to pass the value to a filter.
I have spent hours on this but no luck :( Any help will be greatly appreciated!
The problem is that AJAX function runs separate from the user page. So I guess that when you add the filter it never executes because it's a AJAX call and not building the page. I would do a $_SESSION variable to temporary store the value and use it in the hook like:
function mht_set_partial_payment_amount(){
if (!empty($_POST["partial_payment_amount"]) {
$_SESSION['my-amount"] = $_POST["partial_payment_amount"];
echo json_encode($amount);
}
wp_die(); // Use wp_die for ajax functions.
}
Always add the filter to execute the call, but the code inside only will be done if the $_SESSION variable exists:
add_filter('woo_wallet_partial_payment_amount', function($partial_payment){
if (!empty($_SESSION["my-amount"]) {
//EXECUTE WHAT YOU WANT
};
}
I have a problem with the following code. How do i put 2 included files into 1 line include?
I already tried it like the code below but nothing is shown (blank page). It should show the url.
Url: theme/default/main/index.php (it would be)
application-sql-realtime.php = (should show 'default' or anything else when user changing their themes template it connect to sql)
<?php include('./theme/<?php include_once("config/application-sql-realtime.php");?>/main/index.php');?>
Refer image for code
include_one returns boolean
Maybe can be like this:
<?php
$theme = exec("php config/application-sql-realtime.php");
include("./theme/{$theme}/main/index.php");
?>
But I think you better put it in some class/function
<?php
// inside application-sql-realtime.php you declare a function to return theme name eg: getThemeName
include("config/application-sql-realtime.php");
$theme = getThemeName();
include("./theme/{$theme}/main/index.php");
?>
Make a class with a static or non static method to retrive the value you need (e.g. 'default'). Then you can implement this value in your string to include the first file. Following an example of a static method call:
<?php
$val = EgClass::getPathPart();
include('./theme/'.$val.'/main/index.php');
?>
I'm using the following code in the file main.php:
searchpage = "index.php?k=SEARCH";
include($searchpage);
To call code within index:
if(isset($k)){
$k = $_GET['k'];
if ($k =="SEARCH"){
include("searchpage.php");
}
}
By my understanding this should insert the contents of the file searchpage.php where I called
include($searchpage);
However it just loads main.php again, meaning that k was not set. How does passing ?k=var work in regards to isset() and why does isset reading k as null when I put k=SEARCH in the url when calling the page?
If you need more of the code for context or clarity for the question please let me know thank you.
Try this, I think $k is not set so PHP doesn't go into the "if clause":
if(isset($_GET['k'])){
$k = $_GET['k'];
if ($k == "SEARCH"){
include("searchpage.php");
}
}
main.php
$k="search";
include "index.php";
index.php
if ($k=="search") {
include "searchpage.php";
}
Sorry, I might be missing your point, but from the logic of your code, this is simpler and works fine.
You cannot use this $searchpage = "index.php?k=SEARCH";
If you want to pass parameter you have to pass it from url i.e from address bar only.
So pass parameter in address bar and then include your index.php like this
$searchpage = "index.php";
Then your code wil work fine
Hope this will help you.
In cakephp, how do we specify which theme to use for an Element. I am initializing View object in Controller. I need to pass the element content as ajax response.
Controller :
$view = new View($this);
$view->layout = 'theme2';
$view->theme = 'newNav';
foreach($ctps as $ctpName)
{
$ctp[] = $view->element($ctpName);
}
At first I thought of accessing it as
$ctp[] = $view->element('../Themed/new/Elements/'.$ctpName);
But it obviously does not take care about element's directory. As some of the elements are in app/View/Elements and some are in app/ViewThemed/new/Elements/ directory.
Please suggest.
As per Arilia's suggestion, I am now trying
$this->viewClass = "Theme";
$this->viewPath = 'Elements';
$view = new View($this);
$view->theme = "new";
$view->layout = "theme";
$ctp = $view->element('userprofile');
echo json_encode($ctp);
die;
I am making an ajax call to this code. and it returns
"Element Not Found: Elements/userprofile.ctp"
what I was trying to develop was to render the basic page at first so that it can be cached. and then with the ajax call fetch the parts of UI that are session dependent and then replace the respective elements on browser.
To implement this, I tried fetching cakephp elements in controller, json encoding them and echoing them back. The code above though it worked for a normal dynamic page, it did not work for ajax calls. Cakephp somehow misbehaved here.
Now, as a better alternative, I have moved the code to View itself and I am echoing the json encoded from there. and as expected it is working well. Code is as
app/View/Themed/new/Elements/get_ctps.ctp :
<?php
foreach($ctps as $ctpName)
{
$ctp[] = $view->element($ctpName);
}
echo json_encode($ctp);
die;
?>
Its not a usual case. However, it might be helpful for someone.
Let me first say I've spent a day reading three google pages of articles on this subject, as well as studied this page here.
Ok, here's my dilemma. I have two functions. Both called upon via AJAX. This first one assigns a value to the variable and the second one uses that variable. Both functions are triggered by two separate buttons and need to stay that way. The AJAX and the firing off of the functions work fine, but the variable isn't passed. Here is my code:
if( $_REQUEST["subjectLine"] ) //initiate first function
{
$CID = wpCreateChimpCampaign();
echo $CID; //this works
}
if( $_REQUEST["testEmails"] ) //initiate second function
{
echo $CID; //does not return anything but should contain "apple"
wpSendChimpTest($CID);
}
function wpCreateChimpCampaign () //first function
{
$CID = "apple";
return $CID;
}
function wpSendChimpTest ($CID) //second function
{
echo $CID; //does not return anything but should contain "apple"
}
I'm open to using a class but I haven't had much luck there either. I was hoping to solve this issue without using classes. Thanks for the help in advance!
If you are making 2 separate calls to this file, it may be helpful for you to visualise this as being 2 functions in 2 totally separate files. Although they exist in the same PHP file, because they used called in different calls, they don't retain the value of the variable $CID. Once the file has run, the variable is destroyed and when you call the file again, the value is null again.
So you need to store that variable between calls. You can either store it in a database or store it in a session variable.
So call session_start(); at the beginning of the file, then rather than use $CID, just use $_SESSION['CID'];
I'm not sure where the hold up is. The code you have will work:
$CID = wpCreateChimpCampaign(); // returns 'apple'
wpSendChimpTest($CID); // echos 'apple'
The code looks fine, but are you certain that all requirements are being met so both functions execute?
In other words are you supplying values for both $_REQUEST["subjectLine"] and $_REQUEST["testEmails"]?