I want to make an if statement that if they click a link with "Embed" link type, an onclick event will occur. This is my code, but it doesn't work.
I Have two link types:
External //This link will open in new tab
Embed // This is my problem, i want the embed link(video) to load in my page not open in new page or new tab that is why i need the onclick to work if they click this link type.
<a target="_blank' href="<?php get_option('url') ?>/wpwm-redirect?link_id=<?php $t_link->linkID ?>" <?php if($t_link->link_type == 'Embed') echo ' onclick="ayeLoadVideo('/wpwm-redirect?link_id=<?php $t_link->linkID ?>'); return false;"'; ?>> <?php $t_link->link_title ?> </a>
Change:
echo ' onclick="ayeLoadVideo('/wpwm-redirect?link_id=<?=$t_link->linkID ?>'); return false;"'
to:
echo ' onclick="ayeLoadVideo(\'/wpwm-redirect?link_id=' . $t_link->linkID . '\'); return false;"'
You need to escape the quotes that are inside the string, otherwise they'll end the string.
You can't use <?= inside a string. <? is used for switching from HTML code into PHP code, but you're already in PHP code when you execute echo. Use string concatenation in PHP code.
Related
I have created a custom wordpress post type everything works but my client asked me to insert a function that doenst show the button if the link field is empty that is also working but when I want to display the tekst or link the part where the php is inserted just doesnt shows up what am I doing wrong
I am able to get the data on other parts of this php file but not in this part of the page
<?php
$linktitle = $day_aray=get_field("under_shoe_button_title");
$linkexist = get_field("under_shoe_button_link");
echo($linktitle);
if (empty($linkexist)) {
echo '<html> <p></p></html>' ;
}
else {
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html> <?php echo($linktitle); ?> <html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
}
?>
If you would look carefully, you would notice, that you are echoing a string where, inside the string, you are trying to echo again. Even with little programming knowledge, you should understand, that it is not logical to do that.
The same goes for php opening <?php tag. You opened the tag at start of the page and later on, inside a string, you are trying to open it again. This does not work.
Instead, close the string (or escape it) and then add the echo option.
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html>';
echo($linktitle);
echo '<html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
And please, read the comments to you question and learn basic HTML
There are so many things wrong in your code
Firstly you are using echo inside echo you should use concatenation instead.
so you want to echo it like this
echo '<your html code>'.$linktitle.'<your other html code>';
Also your html code is wrong coz u are using many html tags.
I have a anchor tag that links to a php page, I would like to use special characters in the url parameter title
The string I would like to pass in the url:
Which is better approach to use href="#" or href="javascript:void(0)"
My anchor tag href will look like this:
mypage.php?title=Which is better approach to use href="#" or href="javascript:void(0)"
on my php page, when i echo $_GET["title"]; I only get part of the string:
Which is better approach to use href="
how to display exact title which i used in my anchor tag
You have to enconde the string before sending it to the title variable.
Example:
$title = 'Which is better approach to use href="#" or href="javascript:void(0)"'
echo '<a href="mypage.php?title='. urlencode($title) . '">';
// and to get the title
echo urldecode($_GET["title"]);
Use urlencode() to output your links and urldecode() to echo them in the other page:
First page:
<?php
$link = urlencode('Which is better approach to use href="#" or href="javascript:void(0)"');
echo 'a link';
?>
And on mypage.php you'll do:
<?php
echo urldecode( $_GET['title'] );
?>
The PHP $_GET['title'] is the variable "title" of the get array which are in fact the variables after the ? in an url.
test
this would show TheTitle
But you'll probably want to url escape the title.
Link
I wrote a php page which has two php tags and one script tag inside it .
<?php
$value = $_GET['hash'];
?>
<script>
function execute(){
<?php
$readfile = file($value);
for ($k=0;$k<=count($readfile)-1;$k++){
$cmd = $readfile[$k];
echo $cmd;}
?>
}
</script>
I want to use $value inside another php tag ( like above it has the file I want to open ), but I am not able to do it.Is the scope of variable limited to one php tag ? if yes how can I solve this problem Please help
Your code works perfectly. The variables in one PHP tag is accessible from all other tags, unless you define them inside a PHP function.
The reason you are not seeing the echo on the screen is because the echo prints to the Javascript function.
If you view the source of the generated page, the file contents will be there.
Try this:
function execute(){
<?php
$readfile = file($value);
for ($k=0;$k<=count($readfile)-1;$k++){
$cmd = $readfile[$k];
?>
alert( <?php echo $cmd; ?> );
<?php
}
?>
}
execute();
if $value is a get then you don't need to access it as a file, it should just be a short string.
just above line 7 (the one with $readfile = file...
type:
echo "alert(The hash value is: ".$value.")";
This will make an alert display (as it is in a script tag)
p.s you should have in your opening tag
I have problem and I tried click link then it doesn't work to open link using target: name of iFrame. i dont want use href because im going make show/hide div.
Javascript:
<script type="text/javascript">
<!--//
function godirect(url, targetname)
{
document.getElementById(targetname).src = url;
//frame[targetname].location.href = url;
}
//-->
</script>
in HTML and PHP:
$a=0;
echo 'Click Me!';
echo '<iframe class="iframe_url" id="iframe_url'.$a.'"></iframe>';
How about
<script type="text/javascript">
function godirect(url, targetname) {
window.frames[targetname].location = url;
//OR
//window.open(url,targetname);
return false;
}
</script>
<?PHP
$a=0;
?>
Click Me!
<iframe class="iframe_url" name="iframe_url<? echo $a; ?>" id="iframe_url<? echo $a; ?>"></iframe>
You have to quote strings in JavaScript. You are trying to get the id of the element by passing in a variable which you haven't defined.
You are also using the same quote characters to delimit your HTML attribute value as you are using to delimit your JS strings.
To use the approach you are using, while making the minimum number of fixes to make it work:
echo 'Click Me!';
Using JS for this is a very silly idea in the first place though, and your implementation fails to have any kind of fallback for when JS is not available (which is odd, since you are taking steps to stop browsers which don't recognise the script element from rendering the JS as content text).
You can do this with plain HTML:
<a href="http://www.google.com"
target="iframe_url<?php echo htmlspecialchars($a); ?>">
Click Me!
</a>
i dont want use href because im going make show/hide div.
You can do that as well as having a normal, functioning link. Build on things that work.
Try this:
echo 'Click Me!';
echo '<iframe class=\"iframe_url\" id=\"iframe_url'.$a.'\"></iframe>';
EDIT: What a TW*T. Sorry everyone for wasting your time. Just missed a Google jQuery link on one F'in page. Whoops.
Hi, i have a div containing 3 forms. These should be the only thing on the screen on page load. When any of them are submitted, a graph gets shown below. What i'm trying to do is within the PHP IF statement is make the div disappear that contains the forms. Sound simple?
This is my code:
if($_GET['submit1']){
echo "<script type='text/javascript'>$('#options').css('display','none');</script>";
However, when i do submit one of the forms (therefore a $_GET has occurred) the div is still there??
EDIT:
If i try people answer on one line i get this:
Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$'
But if i put in people's multiline answers, no error, but div still shows!
Why do you want to hide the forms with JavaScript?
Simply do it with PHP:
<?php
if(!isset($_GET['submit1'])) {
?>
//<form> your form HTML here
<?php
} else {
?>
<p>Your submitted data: <?php print_r($_GET); ?></p>
<?php
}
?>
So your forms are only shown if you have NOT submitted one of them. You might have to adjust the parameters if you have multiple forms, for example
if(!isset($_GET['submit1']) && !isset($_GET['submit2'])) {
Edit: If you want to keep your forms after submitting but only hide it, you could do it that way:
<?php
$formsVisible = !isset($_GET['submit1']));
$formsDisplay = $formsVisible ? 'block' : 'none';
?>
<form style="display:<?php echo $formsDisplay; ?>">
<!-- ... --->
</form>
You need to add a DOM ready event:
if($_GET['submit1']) {
echo '<script type="text/javascript">' . "\n";
echo ' $(function() {' . "\n";
echo ' $("#options").hide();' . "\n";
echo ' });' . "\n";
echo '</script>' . "\n";
}
edit
You are getting a parse error because you're using double quotes, so the php parser is reading the dollar sign as a php variable. I would switch to a single quote php syntax to make your life easier:
if($_GET['submit1']){
echo '<script type="text/javascript">
$(function(){
$("#options").css("display","none");
});
</script>';
}
Be sure to wrap your jquery code in the onLoad function $(function(){};