I want to set a PHP cookie through a button click event of JavaScript how can I achieve this. Is there any big minds can help me.
<script>
function openC(){
<?php setcookie('z', 'on', time() + (86000), "/" ); ?>
oopen();
}
</script>
<div class="row">
<div class="col-12 p-rel">
<button type="button" onclick="openC()" id="opner" class="btn hide btn-dark "><i
class="fa fa-bars"></i></button>
</div>
</div>
above is my code if I try to echo my cookie in another page like my header page I get nothing
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--Favicon-->
<link rel="icon" href="<?= base_url() ?>assets/new_assets/images/favicon.png" type="image/gif" sizes="16x16">
<link href="<?= base_url() ?>assets/new_assets/css/style.css" rel="stylesheet" type="text/css"/>
<!--Site Title-->
<title><?php echo!empty($title) ? $title : ""; ?></title>
<p> <?php echo $_COOKIE["z"]; ?></p>
</head>
<script type="text/javascript">
var url = "<?php echo base_url(); ?>";
</script>
Related
<?php
$currency = file_get_contents('https://api.pro.coinbase.com/currencies');
$result = json_decode($currency);
$totalCurrency = array();
foreach($result as $key){
if($key->details->type == 'crypto'){
array_push($totalCurrency, $key);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aditya Dev ~~ Coinbase Deposit By PHP</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<div class="main">
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<?php foreach($totalCurrency as $key): ?>
<li><a class="dropdown-item" href="#"><?= $key->id; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="index.js"></script>
</body>
</html>
In the PHP I fetch all crypto coin symbols from API and store it Here in this line $totalCurrency = array(); and then I run a loop to create a dropdown list like this
I want that if I click any currency from there javascript send an alert like this alert(symbol)
I am quite confused about how to do this, it's not a button its tag, please help me
I'm working on my first page for my exam and i must use the undersceleton theme.
I have created a custom .php file but the code won't work, the javascript doesn't seem to pick up the post information from WP. If i use the same code on the index.php it works just fine.
According to what information i managed to gather i must call in the added .php for the header and footer, which i did and it still doesn't work. The header with the nav bar and footer are loading perfectly but the posts won't.
I also tried to copy the content from the page.php or content.php nothing seems to work.
Any ideas?
<!DOCTYPE html>
<?php /* Template Name: ekszerek */ ?>
<?php get_header(); ?>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="https://fonts.googleapis.com/css?family=Domine:400,700|Roboto" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<div class"container">
<div class="row">
<div class="col-sm-4 col-md-4 grid_ss">
<?php /* Variable for row creation */
$startRow = true;
$postCounter = 0; ?>
<?php /* Loop start*/ if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ($startRow) {
echo '<!-- START OF INTERNAL ROW --><div class="row">';
$startRow = false; } ?>
<?php $postCounter += 1; ?>
<div class="col-sm-4">
<div class="paper">
<div class="poster" >
<?php if ( has_post_thumbnail() ) : ?>
<a class="img_thumb" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 380, 288 ); ?>
</a>
<?php endif; ?>
</div>
<div class="posted_on">
<?php underskeleton_posted_on(); ?>
</div>
<h1 class="paper_h1">
<?php if ( is_single() ) { the_title( '<h1 class="entry-title">', '</h1>' );
} else {
the_title( '<h2 class="entry-title">', '</h2>' );
} if ( 'post' === get_post_type() ) : ?>
<?php endif; ?>
</h1>
<hr/> <!-- Text separator -->
<div class="paper_p">
<?php echo get_excerpt(); ?>
</div>
<a class="btn" href=(<?php the_permalink(); ?>)>Megnyit</a>
<div class="space"></div>
<h2 class="paper_h2">
<!-- .entry-meta -->
</h2>
</div>
</div>
<?php /* Check if counter hits 3, if yes start new row */
if ( 3 === $postCounter ) {
echo '</div><!-- end of row -->';
$startRow = true;
$postCounter = 0; } ?>
<?php /* End of the loop */ endwhile; ?>
<?php /* If you are returning an odd number of posts (i.e., anything other than a multiple of 3), we will need to close the row div.*/
if ($postCounter !== 0 ) { echo '</div><!-- end of row -->'; } ?>
<?php else: ?>
<div class="page-header"><h1>Uh Oh!</h1></div>
<p>Sorry, for some reason the contents of this page isn't displaying.</p>
<?php endif; ?>
</div>
</div>
<?php
get_footer();
I'm trying to use Ajax for a form but it seems not to be working. I'm not sure if it's because the file is php but being shown as a javascript file, or something along those lines but I would like to get this fixed. Thanks in advance.
login/index.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo SERVER_NAME; ?> | <?php echo $this->title ?></title>
<link rel="stylesheet" media="screen" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="<?php echo URL; ?>/public/css/bootstrap.min.css"></link>
<link rel="stylesheet" href="<?php echo URL; ?>/public/css/css.login.php" />
<script type="text/javascript" src="<?php echo URL; ?>/public/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo URL; ?>/public/js/bootstrap.min.js"></script>
</head>
<body>
<div id="login" class="container">
<div class="module">
<div class="module-header">
<h4>Login</h4>
</div>
<div class="module-body module-padding">
<form class="form" method="post" action="<?php echo URL;?>/actions/login.php">
<input type="text" name="login-username" placeholder="Username">
<br />
<input type="password" name="login-password" placeholder="Password">
<br />
<input type="submit" name="submit" placeholder="Login" class="pull-right">
</form>
</div>
</div>
<div class="msg">
</div>
</div>
<script type="text/javascript" src="<?php echo URL; ?>/public/js/user-login.php"></script>
</body>
</html>
user-login.php (acts as js)
<?php
header('Content-Type: application/javascript');
require "../../Application/Configuration/config.php";
?>
$(window).load(function() {
$('.form').submit(function(event) {
var formData = {
'login-username': $('input[name=login-username]').val(),
'login-password': $('input[name=login-password]').val()
};
$.ajax({
type: "POST",
url: "<?php echo URL; ?>/actions/login.php",
data: formData,
success: function (json_data) {
var data_array = $.parseJSON(json_data);
if (data_array['error'] == false) {
$('.msg').css('display', 'block');
$('.msg').addClass('msg-success');
$('.msg p').html(data_array['text']);
$('.msg').fadeOut(4000);
var delay = 4000;
setTimeout(function() {
window.location.replace("../index.php");
}, delay);
} else {
$('.msg').css('display', 'block');
$('.msg').addClass('msg-failure');
$('.msg p').html(data_array['text']);
$('.msg').fadeOut(4000);
}
},
fail: function () {
alert("failed to send");
}
});
});
});
I got this error from my bootstrap.js. what is the error and how can i fix this?
GET http://localhost/hr/public/js/booststrap.js index:12
status 404
My header code is,
<!--DOCTYPE html-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Login</title>
<link rel="stylesheet" href="<?php echo base_url();?>public/css/bootstrap-responsive.min.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="<?php echo base_url()?>public/js/jquery.js"></script>
<script src="<?php echo base_url()?>public/js/booststrap.js"></script>
</head>
<body>
<header>
Header
</header>
i am using code igniter on xampp.
I think you need to change the script tags to this:
<script src="<?php echo base_url();?>public/js/jquery.js"></script>
<script src="<?php echo base_url();?>public/js/bootstrap.js"></script>
And, as suggested by #wolfgang1983 make sure to edit the base_url in the config file to http://localhost/hr/
i have problem with including javascript in joomla 3 template code. I am trying to create slider menu with http://9bitstudios.github.io/flexisel/. Outside of joomla with only html and java code, menu works great. But when i try to implement into joomla template i cant get it working.
My template code:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/reset.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/style.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/flexisel.css" type="text/css" />
<?php
JHtml::_('jquery.framework');
?>
<script type="text/javascript" src="templates/<?php echo $this->template ?>/js/jquery.flexisel.js"></script>
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
$("#flexiselDemo1").flexisel();
});
</script>
</head>
<body>
<div id="page">
<div id="head">
VOSSP
</div>
<div id="main-menu">
<jdoc:include type="modules" name="main-menu" />
</div>
<div id="footer">
</div>
</div>
</body>
</html>
I tryed using of $document->addScriptDeclaration and $document->addScript, from http://docs.joomla.org/Adding_JavaScript, but no change.
You are importing jQuery in noConflict mode, so try changing this:
$(window).load(function() {
$("#flexiselDemo1").flexisel();
});
to this:
jQuery(document).ready(function($) {
$("#flexiselDemo1").flexisel();
});
Note: go back to using JHtml::_('jquery.framework');