I am using this code to display woocommerce custom field on frontend:
// DISPLAY Source Product URL ---------------------------------
echo '<div class="woo_echo">';
echo '<div class="woo_echo_inner">';
echo "<span style='font-weight:600;'>". __( 'Source Product URL:</span> <span> ', 'woocommerce' ) . $_p_source_url ."</span>";
$_p_source_url = get_post_meta($product_id, "_p_source_url", true);
echo '</div>';
echo '</div>';
It works very well but I would like
. $_p_source_url .
to be clickable link. Is it possible to wrap it with a tag?
In this example source url is original url of scraped product not woocommerce product url.
You need something like this :
echo "<a href='$YOUR_LINK_PRODUCT_URL'>product</a>";
EDIT
echo '<div class="woo_echo">';
echo '<div class="woo_echo_inner">';
echo "<span style='font-weight:600;'>". __( 'Source Product URL:</span> <span> ', 'woocommerce' ) . $_p_source_url ."</span>";
$_p_source_url = get_post_meta($product_id, "_p_source_url", true);
echo "<a href='$_p_source_url'>product</a>";
echo '</div>';
echo '</div>';
Related
I have the follow form in Codeigniter:
The controller:
public function item($alias = NULL){
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Edit menu';
$data['menu_item'] = $this->menu_model->get_menu($alias);
$data['articole'] = $this->menu_model->get_articole();
$data['menuactive'] = $this->menu_model->get_menuactiv();
$data['errors'] = $this->form_validation->error_array();
$this->form_validation->set_rules('position','Position','required');
$this->form_validation->set_rules('position','Position','numeric');
$this->form_validation->set_rules('name','Name','required');
if ($this->form_validation->run() === FALSE) {
$data['name'] = $data['menu_item']['name'];
$this->load->view('templates/header', $data);
$this->load->view('templates/youarehere', $data);
$this->load->view('templates/menu', $data);
$this->load->view('templates/admin', $data);
$this->load->view('menu/item', $data);
$this->load->view('templates/footer');
}
else {
$this->menu_model->update_menu();
redirect('menu');
}
}
The item view is:
<?php echo validation_errors(); ?>
<?php echo form_open('menu/item'); ?>
<?php echo form_label('ID ', 'id'); ?>
<?php echo form_input('id', $menu_item['id'], 'readonly'); ?><br><br>
<?php echo form_label('Name ', 'name'); ?>
<?php echo form_input('name', $menu_item['name']); ?><br><br>
<?php echo form_label('Position ', 'position'); ?>
<?php echo form_input('position', $menu_item['position']); ?><br><br>
<?php foreach($articole as $articole_item):
$articol1[] = $articole_item['id'] . ' ' . $articole_item['title'];
endforeach; ?>
<?php echo form_label('Associated article ', 'associated_article'); ?>
<?php echo form_dropdown('associated_article', $articol1, $menu_item['articol_asociat']); ?><br><br>
<?php echo form_label('Menu activ ', 'activ'); ?>
<?php echo form_checkbox('activ', '1', TRUE); ?><br><br>
<input type="submit" name="submit" value="Save menu"/>
</form>
In this view I edited menu items. Everything works fine when when everything is right. When I introduce something wrong in a field, like string into "position" field, the form redirect to item view, but with empty fields and with the error message. I want to keep what is entered in field and the error message.
What is wrong with my code?
Change your form :
<?php echo form_label('ID ', 'id'); ?>
<?php echo form_input('id', set_value('id'), 'readonly'); ?><br><br>
<?php echo form_label('Name ', 'name'); ?>
<?php echo form_input('name', set_value('name')); ?><br><br>
<?php echo form_label('Position ', 'position'); ?>
<?php echo form_input('position', set_value('position')); ?>
set_value() replace your old values
i am displaying the daily report submitted by the user now i want to mail the same to email when the send email button is clicked. how can i do that in PHP ?
i used the following code
extract($_REQUEST);
if(isset($send_mail)){
$edata= $_POST['send_msg'];
echo "<script type='text/javascript'>alert('$edata');</script>";
$ka_semail=$_SESSION['user_email'];
$subject = "Report";
$body = $edata;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Info <'.$ka_semail.'>' . "\r\n";
$mchk= mail($ka_semail, $subject, $body, $headers);
if(isset($mchk)){
echo "<script type='text/javascript'>alert('Your data Sent sucessfully');</script>";
header("location:reports.php");
}
}
?>
<body>
<div id="main">
<header>
<div id="logo">
<div id="logo_text">
<a href="index.html">
<div style="background:#2A0000"><img src="images/kreamsoftlogo.png"/></a></div>
</div>
</div>
<?php include'nav.php'; ?>
</header>
<div id="site_content">
<div id="email-data">
<div id="content">
<div class="content" style="min-height:385px; width: 100%" >
<h1>Daily Report </h1>
<?
$current_date = date("d/m/Y");
$current_user = $_SESSION['user_login'];
$find = mysql_query("select * from k_dailyreport where kr_user='$current_user' AND kr_date='$current_date'");
?>
<div class="content_item">
<ul>
<?php
$numrow=mysql_num_rows($find);
if($numrow>0){
$sino = 0;
echo "<table border='0' width='100%'>";
echo "<tr class='head'>";
echo "<th>S.No</th>";
echo "<th>Project</th>";
echo "<th>Process</th>";
echo "<th>Process Date</th>";
echo "<th>Current Duration</th>";
echo "</tr>";
$sno=0;
while($row = mysql_fetch_array($find)){
$sno=$sno +1;
$sino++;
$cls = ($sino%2==0) ? "even" : "odd";
echo "<tr class='t1'>";
echo "<td>$sno</td>";
echo "<td>".$row['kr_project']."</td>";
echo "<td>".$row['kr_process']."</td>";
echo "<td>".$row['kr_rtime']."</td>";
echo "<td>".$row['kr_ctime']."</td>";
}?></td>
<?php
echo "</tr>";
?><form name="test" method="post"enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p style='padding-top: 15px;margin-right: 50px; float:right'><input class='submit' id="sendEmail" type="submit" name='sendmail' value='Send Mail' />
<input type="hidden" name="send_mail" value="send_mail" />
<input type="hidden" name="send_msg" value="<?php
$numrow=mysql_num_rows($find);
if($numrow>0){
$sino = 0;
echo "<table border='0' width='100%'>";
echo "<tr class='head'>";
echo "<th>S.No</th>";
echo "<th>Project</th>";
echo "<th>Process</th>";
echo "<th>Process Date</th>";
echo "<th>Current Duration</th>";
echo "</tr>";
$sno=0;
while($row = mysql_fetch_array($find)){
$sno=$sno +1;
$sino++;
$cls = ($sino%2==0) ? "even" : "odd";
echo "<tr class='t1'>";
echo "<td>$sno</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "<td>".$row[3]."</td>";
echo "</tr>";
}echo "</table>";}?>" /></p>
</form>
<?
}else{
?>
<center><img style="text-align:center" src="images/no_record.gif" /></center>
<?
}
echo "</table>";
?>
</li>
</ul>
</div>
</div> </div>
</div>
</div>
i want to mail the entire table with data
Without knowing anything about your code, I can perhaps at least guess as to the structure of what builds this table. Maybe something along the lines of this?:
writeTableHeader();
foreach ($values as $value) {
writeTableRow($value);
}
writeTableFooter();
Maybe even abstracted into its own higher-level function?:
function writeTable($values) {
$result = '';
$result .= buildTableHeader();
foreach ($values as $value) {
$result .= buildTableRow($value);
}
$result .= buildTableFooter();
return $result;
}
Any such function or abstraction can be used to construct the HTML for the email body as well...
// ... previously building the overall email body
$mailBody .= writeTable($values);
// ... maybe some more email body elements as well
mail($to, $subject, $mailBody);
Styling the email will be another story, of course. It's best not to rely on linked resources in an HTML email, those tend not to be requested by mail clients as they're often abused by spammers and the like. You can perhaps include the style sheet(s) as an "embedded resource" in the email, though in most cases I think inline styling is probably best for emails. (Some mail clients might not even load an embedded resource, at least not without first prompting the user, which isn't an ideal user experience.)
Assuming you don't want to duplicate much code, the above method can be abstracted using the Form Template Method refactoring pattern (example here, among others).
I guess the point I'm getting at is that the email doesn't send the web page, but rather the web page and the email are both independent "views" of the underlying data. Common code between them can be abstracted and shared of course, but trying to re-use a webpage itself in an email is over-complicating the situation.
'Duration' is a column in the table, which is 'required'
form:
<div class="row">
<?php echo $form->labelEx($model,'duration'); ?>
<?php
echo "<select>";
echo "<option value=\"1\">1</option>";
echo "<option value=\"1.5\">1.5</option>";
echo "<option value=\"2\">2</option>";
echo "<option value=\"2.5\">2.5</option>";
echo "<option value=\"3\">3</option>";
echo "</select>";
?>
<?php echo $form->error($model,'duration'); ?>
</div>
When i choose an option it comes with the error 'Duration cannot be blank'. How to make it read the value?
Make sure the name of the select is of Model[duration]
You need to have:
echo '<select name="ModelName[duration]">';
Also please don't mix PHP vanilla code in the Yii views, and use the methods provided by Yii.
I would do something like this:
echo CHtml::dropDownList('duration', $model, array('0' => 'Private', '1' => 'Public'));
Or even better:
echo $form->dropDownList($model, 'placement', $model::$def_duration, array('prompt' => 'Select'));
where def_duration would be a key=>value array defined in your model.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
PHP SCRIPT issue with passing the uploaded image to facebook->api function
I have this code and its working awsomely fine just and just only one problem i am not able to pass my uploaded image to facebook->api (whether its valid or not) and the following always echo
echo 'Only jpg, png and gif image types are supported!';
i even remove the check on image type and try to get the image from
$img = realpath($_FILES["pic"]["tmp_name"]);
but $img gets nothing in it and uploads a by default empty image on facebook as my page
Kindly check my following code and let me know what should is wrong with my code so i'll become able to upload images
<?
require 'src/facebook.php';
$app_id = "364900470214655";
$app_secret = "xxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'fileUpload' => true,
));
$user = $facebook->getUser();
//echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
exit;
}
else {
$accounts_list = $facebook->api('/me/accounts');
echo "i am connected";
}
$valid_files = array('image/jpeg', 'image/png', 'image/gif');
//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
if($account['id'] == 194458563914948){ // my page id =123456789
$access_token = $account['access_token'];
echo "<p>Page Access Token: $access_token</p>";
}
}
//posting to the page wall
if (isset($_FILES) && !empty($_FILES))
{
if( !in_array($_FILES['pic']['type'], $valid_files ) )
{
echo 'Only jpg, png and gif image types are supported!';
}
else{
#Upload photo here
$img = realpath($_FILES["pic"]["tmp_name"]);
$attachment = array('message' => 'this is my message',
'access_token' => $access_token,
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'example.org',
'description' => 'this is a description',
'picture' => '#' . $img,
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$status = $facebook->api('/194458563914948/feed', 'POST', $attachment); // my page id =123456789
var_dump($status);
}
}
?>
<body>
<!-- Form for uploading the photo -->
<div class="main">
<p>Select a photo to upload on Facebook Fan Page</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<p>Select the image: <input type="file" name="pic" /></p>
<p><input class="post_but" type="submit" value="Upload to my album" /></p>
</form>
</div>
</body>
Creating a New Album and Adding a Photo
This is the scenario where you upload a photo to the ALBUM_ID/photos Graph API endpoint. The user interface for this example allows the user to select a photo and add a caption before submitting the new photo.
Using PHP:
<?php
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$post_login_url = "YOUR_POST-LOGIN_URL";
$album_name = 'YOUR_ALBUM_NAME';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
$code = $_REQUEST["code"];
//Obtain the access_token with publish_stream permission
if(empty($code))
{
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($post_login_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url .
"'</script>");
}
else {
$token_url= "https://graph.facebook.com/oauth/"
. "access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Create a new album
$graph_url = "https://graph.facebook.com/me/albums?"
. "access_token=". $access_token;
$postdata = http_build_query(
array(
'name' => $album_name,
'message' => $album_description
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false,
$context));
// Get the new album ID
$album_id = $result->id;
//Show photo upload form and post to the Graph URL
$graph_url = "https://graph.facebook.com/". $album_id
. "/photos?access_token=" . $access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url. ' "method="POST">';
echo 'Adding photo to album: ' . $album_name .'<br/><br/>';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo 'Say something about this photo: ';
echo '<input name="message" type="text"
value=""><br/><br/>';
echo '<input type="submit" value="Upload" /><br/>';
echo '</form>';
echo '</body></html>';
}
?>
I'm trying to do different feeds into one area that I switch with jquery tabs. I have a feed template and only need to switch the rss feed url inside of it each time. I tried to set a value to the url on my index page and then echo it inside the feed but I'm obviously not doing this right. Whats wrong with my approach?
<----Index Page--->
<div class="news-feed"><?php $url = "http://mysite.com/category/news/feed/"; ?><?php locate_template( array( 'feeds/news-feed.php' ), true ) ?></div>
<-------FEED-------->
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed('$url');<---WHERE I NEED MY CUSTOM URL
if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity(5);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
endif;
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo esc_html( $item->get_title() ); ?>'>
<?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?>
<?php echo esc_html( $item->get_title() ); ?></br>
<span style="color:#e2e2e2"><?php echo shorten( $item->get_description (),140 ); ?></span></a>
</li>
<?php endforeach; ?>
</ul>
You need to change
fetch_feed('$url');
to
fetch_feed($url);
Single quoted strings in PHP do not have variables inside them expanded.