I need to insert some markup inside page based on whether a URL Query Var exists or not. I'm trying to insert the code inside a shortcode like so:
//Create Shortcode for join page error message
add_shortcode( 'join_error', 'av_join_error' );
function av_join_error(){
$joinresult = $_GET["result"];
if($joinresult){
echo "<p class='alert'>Your payment was declined. Please double check your details and try again.</p>";
}
}
It's not working, hopefully someone can point me in the right direction!
The code you posted is mostly fine, you will need to post more.
First do print_r($_GET) and make sure the array is actually being set.
Also, shortcodes should always return and not echo. Using return keeps the shortcode output where it is in the document/page (echo will output it to the top).
more about that here under Output: http://codex.wordpress.org/Shortcode_API
Try
//Create Shortcode for join page error message
function av_join_error(){
$joinresult = $_GET["result"];
if($joinresult){
echo "<p class='alert'>Your payment was declined. Please double check your details and try again.</p>";
}
}
add_shortcode( 'join_error', 'av_join_error' );
Related
I have design a webpage to and make all necessary code in admin section. How do I call this value to show on the customer page in the number format?
I am trying to show the amount in double eval. I mean $750,100.15.
When a customer logs in the value will be shown on their page. I used the following code it work.
<?php echo $_SESSION['hlmgt_user']['amount']; ?>
This prints out $750100.15, but I need it to print $750,100.15. I am using the above code to call the value on customer page.
How to fix the below code to get it working?
<?php echo $_SESSION['hlmgt_user']number_format($row['balance'], 2); ?>
try this maybe helpful
<?php
$number = "750100.15";
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
?>
OUTPUT
$ 750,100.15
I think you should look about the "number_format" or "money_format" function in PHP here:
https://php.net/number_format
https://php.net/money_format
i want to show the status of commentator in comment page of wordpress
i am trying to display simple message [online/offline] according to its status.
right now i am using below code
<?php
$user_id = get_comment(get_comment_ID())->user_id;
if ( is_user_logged_in($user_id) )
{
echo 'Online';
} else {
echo 'Offline';
}
?>
but the above code is not working. it only show text (Online) and not working properly. i think there is some error in above code can anybody correct it for me.
working on a small project and having a small problem. i am querying mysql, i am able to get the array and everything works well but i am adding a additional condition if returns 0 or id does not match the query then redirect.
This is what i have so far.
$q = "SELECT TEST.*,
EMPLOYEE.EMP_ID
FROM TEST
LEFT JOIN EMPLOYEE ON TEST.EMP_ID = EMPLOYEE.EMP_ID
WHERE ITEM_ID=".$db->qstr($item_id);
if(!$item_id = $db->execute($q)){
force_page('system', 'Nothing found');
exit;
} else {
$view = $item_id->GetArray();
}
return $view;
}
so the above returns the array, query grabs $item_id from the url so it could be anything. i would like to check if that id exists if not then force the page as shown in the above. any suggestion on what i am doing wrong?
If you want to redirect you can use header function
header("Location: put_your_url_here");
e.g.
header('Location: /mypage.php');
There is no function such as force_page in PHP. You can use header to redirect user to another page. Modify your if condition as
if(!$item_id = $db->execute($q)){
header("Location: url_to_redict");
die();
}
header("Location: Your_url"); will help you to redirect based on your condition.but make sure that you have not echoed any thing before the header otherwise it won't redirect.
I don't think there is any function like force_page(); in php
You need to redirect like header("Location: Your_url");
And If you have function force_page(); please post code of that.
I am making a website in CodeIgniter and for one of these pages I need to insert information into a database, however every time I enter information into my form and submit it, the page refreshes like it had been submitted but nothing enters the database.
Controller:
public function insertjob()
{
$this->load->helper('form');
$data['title']="Add a new job";
$this->load->view("insertjob", $data);
}
public function addingjob()
{
$jobtype=$this->input->post('jobtype');
$jobinfo=$this->input->post('jobinfo');
$this->load->model("cmodel");
if($this->cmodel->addjob($jobtype, $jobinfo)){
$data['msg']="New job addition successful";
}else{
$data['msg']="There was an error please try again";
}
$this->load->view("confirmation",$data);
Model:
function addjob($jobtype,$jobinfo)
{
$newjob=array("jobtype"=>$jobtype,"jobinfo"=>$jobinfo);
return $this->db->insert('clientjobs', $newjob); exit;
View:
</p>
<?php
echo form_open('client/insertjob');
echo form_label('Job:', 'Job');
echo form_input('jobtype');
echo form_label('Job information:', 'Job information');
echo form_input('jobinfo');
echo form_submit('Add job', 'Submit Post!');
echo form_close();
?>
Try removing the exit from your model:
function addjob($jobtype,$jobinfo)
{
$newjob=array("jobtype"=>$jobtype,"jobinfo"=>$jobinfo);
return $this->db->insert('clientjobs', $newjob);
}
It's not neccessary and could be breaking the database class, as well as halting any execution for the application.
Here's your problem:
echo form_open('client/insertjob');
If you look at your HTML code in your browser, you'll see something like this:
<form action="client/insertjob">
There will probably be a whole bunch of other attributes in your form tag - they're not important for this answer.
That action attribute is telling the browser where to go after you click submit. Where is it going? Back to the insertjob method. But it needs to go to your addingjob method - that's where the database update is actually being done. So change the form_open call to:
echo form_open('client/addingjob');
As I see your are using 2 controller functions for posting, page 1 to page 2. You have error on form open you should post your data to addingjob not insertjob.
echo form_open('client/addingjob');
will fix your issue but I highly recommend you to use, one controller for form submit. Below code will send post to same url. And you could add some attributes on it.
<?php
$attributes = array('class' => 'form-horizontal');
echo form_open($this->uri->uri_string(),$attributes); ?>
I need to add a notification to this page saying " Thank you for your feedback"
However,the notification did not appear at the correct place,which is above the form.
This is my code.
$message="tq 4 feedback";
$common->display_message($message);
This is where the feedback form.
The function i'm using is
function display_message($message) {
print $message;
}
Thanks
Not sure why if you have the message already you are passing it to a function to display, but you need to "return" the variable from the function. Then you can echo it out wherever you need to.
function display_message($message) {
return $message;
}
To call it:
$message="tq 4 feedback";
$returned_message = $common->display_message($message);
And place it where you want:
echo $returned_message;
or just:
$message="tq 4 feedback";
echo $common->display_message($message);
It's probably an issue with your view, to be honest. What's your view look like?