Hello I have the below php code:
if (isset($_POST['prano'])) {
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('aplikacioni');
$mbajtesi = $_SESSION['mbajtes'];
for ($i=1; $i<=$mbajtesi; $i++) {
if (empty($notat[$i])) {
$emp = "emp";
}
}
if ($emp == "emp") {
echo ("<script language = 'javascript'> window.alert('Something!!!');window.location.href='Snotat.php';</script>");
exit();
}
}
Now, this code means: When I press the button named 'prano' then displayed a table with input values.The user must fulfill all values..If not then he gets a message...
So I don't want after the dialog message to disappear the table [remember the table appear when press button 'prano']...just I want to appear a dialog message without disappear the table..I've tried location.reload() but not work..any idea?
Your code is OK. Can you check your $_SESSION['mbajtes'] & confirm that, session_start(); line is exist in top of your page?
The problem is that you don't need to reload the page. You should use javascript/jQuery to insert an element to the body (for example) with that message.
Example:
<?php if ($emp == "emp") { ?>
<script>
jQuery(document).ready(function($){
$('body').prepend('<div>Your message Here</div>);
});
</script>
<?php } ?>
Remember to add jQuery to your header or footer.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
Related
So I have this PHP page, with at the start some unimportant stuff and a session opening :
<?php
session_start();
?>
I want the disconnect button to appear only if the user is already connected, which means that $_SESSION['Pseudo'] is set. If this is the case, I create a button, and bind to that button a function to destroy the session. The problem is, each time I go on this page, the session is destroy, even though it's in a condition.
Here's my code :
<?php
if (isset($_SESSION["pseudo"])) {
echo '<p><button type="button" id="deco">Disconnect</button></p>';
}
?>
<script>
let btn = document.getElementById('deco');
if (btn) {
btn.addEventListener('click', updateBtn);
function updateBtn() {
<?php
session_destroy();
?>
window.location.href = "/"
}
}
</script>
Any clue ?
You cannot combine PHP within Javascript like that.
When you're doing , it's not a part of the Javascript. It's PHP code and is executed as part of the PHP code in the file.
This means that it has nothing to do with the javascript aspect. your updateBtn function is effectively, when the page source code loads:
function updateBtn() { window.location.href = "/" }
What you really want to do is make it so that when someone clicks the button, it takes them to a logout page or a page with a logout query param.
eg.
<?php
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_destroy();
echo 'You have successfully logged out!';
}
if (isset($_SESSION["pseudo"])) {
echo '<p><button type="button" id="deco">Disconnect</button></p>';
}
?>
<script>
let btn = document.getElementById('deco');
if (btn) {
btn.addEventListener('click', updateBtn);
function updateBtn() {
window.location.href = "/?action=logout"
}
}
</script>
I'm using the turn.js to make a catalog. I grab the pages from the database with PHP and I want to make some control buttons like search specific page. How can I parse the value from the searchbox to take the place of number 10 here $("#flipbook").turn("page", 10); and run it?
<div class="flipbook-viewport">
<div class="container1">
<div class="flipbook">
<?php
if (isset($_GET['eb_catalogs_id'])){
$catalogos_id = $_GET['eb_catalogs_id'];
$query= "SELECT c_catalog_name FROM eb_catalogs WHERE c_id = $catalogos_id";
$test= $conn->query($query);
$catalogname =$test->fetchColumn();
$query1 = ("SELECT * FROM eb_catalog_".$catalogname."");
$pages = $conn->query($query1);
$i = 1;
foreach($pages as $page){
echo "<div class='p".$i."' style='background-image:url(https://untuneful-carload.000webhostapp.com/img/catalogs/".$catalogname."/".$page['eb_catalog_imgs'].")'></div>";
$i++;
}}else{
echo "nothing";
}
?>
</div>
</div>
</div>
<script type="text/javascript">
function loadApp() {
// Create the flipbook
$('.flipbook').turn({
width:922,
height:600,
elevation: 50,
});
}
// Load the HTML4 version if there's not CSS transform
yepnope({
test : Modernizr.csstransforms,
yep: ['js/turn.js'],
nope: ['js/turn.html4.min.js'],
both: ['css/basic.css'],
complete: loadApp
});
alert("The current page is: "+$("#flipbook").turn("page"));
</script>
here is the code of the page so far.. I know how to make an input field but I dont know how to parse the value of the input field to the function that jumps to the specific page the user wants.
If you pass the page number to next page, you may get it using $_post or $_get and execute it on page load:
<script>
$(window).on("load",function(){
$("#flipbook").turn("page", <?php echo ($_GET["page"]) ?>);
})
</script>
If you are in the same page and just want to flip the book, you can easily get the number using val():
<input id="pageNumber">
<button onclick="flipPage()">GO</button>
<script>
function flipPage(){
var pageNumber=$('#pageNumber').val();
$("#flipbook").turn("page", pageNumber);
}
</script>
When I click a button, I'm trying to get the name of the button to display on the next page. So far, I've managed to display the button name in an alert box but not sure how to get it to appear on another page.
<script>
$(document).ready(function(){
$("#test").click(function(){
alert("Text: " + $("#test").text());
});
});
</script>
The code below gets modules that the logged in user is registered to and displays two buttons. I'm trying to display the button label(subject names) on another page rather than in the alert box. So when I click on a button, the label name appears on the next page.
$sql = DB::getInstance()->get('modules', array('username','=' ,$user->data()->username));
if(!$sql->count()){
echo 'No data';
}else {
foreach ($sql->results() as $sql){ ?>
<p> <?php echo $sql->name; ?></p>
If you are trying to navigate to another page on click, you can just modify your jquery event handler to this and pull it out of the query params on the next page.
$(document).ready(function(){
$("#test").click(function(){
window.location = "your_next_page.php?name=" + $("#test").text();
});
});
on your other page.
<?php
echo $_REQUEST['name'];
?>
Save the $sql->name to session data and use this another page
$sql = DB::getInstance()->get('modules', array('username','=' ,$user->data()->username));
if(!$sql->count()){
echo 'No data';
}else {
foreach ($sql->results() as $sql){
$_SESSION['name'] = $sql->name;?>
<p> <?php echo $sql->name; ?></p>
another_page.php
session_start();
echo $_SESSION['name'];
It's part of my view. Me need transmit input name in on which i click.
Below is a script that will get the name input after click
<div class="form_hint"><?=form_error('this get value from javascript after click')?></div>
<?php echo form_open("onenews/" . $onenews['id'] . "#signup", $form_reg['main_form']); ?>
<?php echo form_input($form_reg['login'], $this->form_validation->set_value('login')) ?>
<?php echo form_input($form_reg['email'], $this->form_validation->set_value('email')) ?>
<?php echo form_input($form_reg['password']) ?>
<?php echo form_input($form_reg['conf_password']) ?>
<?= MY_Controller:: create_captcha(); ?>
<?php echo form_input($form_reg['captcha']) ?>
<?php echo form_input($form_reg['submit']) ?>
<?php echo form_close(); ?>
</div>
</div>
jq
<script type="text/javascript">
$(function(){
var curInput = '';
$('#form_reg').find('input').on('click', function(){
curInput = $(this).attr("name");
});
})
</script>
Or i must use ajax?
Thanks!
Your question is not clear at all, but I assume you want to dynamically change the content of the form_hint div. You can't do that with PHP. Once PHP renders the page, it shuts down and does nothing more. So the only way to make PHP show that message is after the form submit, but then you lose your click data. There is a way to save the clicked element in a session for example, but that would be a really bad solution.
So the best solution would probably be to list all the hints in a JavaScript variable, and call the appropriate one upon the click event, and fill the form_hint div with it.
$('.form_hint').text(yourAppropriateMessageHere);
An example with a hidden div for the login input field with exactly how you described would be:
<div class="form_text_login"><?=form_error('login')?></div>
JS
var loginMessage = $('.form_text_login').text();
// list others here
// then make a tree with switch/case or if/else
if (curInput == 'login') {
$('.form_hint').text(loginMessage);
}
else if (curInput == 'email') {
// do the same with the email message, etc.
}
I have an if statement that currently has an alert pop up when the next button on the page is clicked. Im not sure what i have to remove to just have the alert go away. I still need the button to take you to the next page. No matter what I adjust, the end result is the button no longer works. Here is the code:
$('.dab_button').click(function(){
if($('[name=select_value1]').val()=='' ||
$('[name=select_value2]').val()=='' ||
$('[name=select_value3]').val()==''){
alert('Please select your gift choices for each or the three levels.');
} else{
<? if($members_info['individual']=='no'):?>
window.location.href = "/dab/profile";
<? else:?>
window.location.href = "/hq/edit_page";
<? endif;?>
}
});
Just comment it out?
$('.dab_button').click(function(){
if($('[name=select_value1]').val()==""||$('[name=select_value2]').val()==""||$('[name=select_value3]').val()==""){
; // do nothing
// alert('Please select your gift choices for each or the three levels.');
} else{
<? if($members_info['individual']=='no'):?>
window.location.href = "/dab/profile";
<? else:?>
window.location.href = "/hq/edit_page";
<? endif;?>
}
});
But I stronly recommend to give some feedback to the user when the button does nothing (does not navigate away), because they have not filled out all inputs. If you wanted to navigate in any case, just remove that if-statement (note that you also have serverside processing code, which has nothing to do with the javascript):
$('.dab_button').click(function(){
<? if($members_info['individual']=='no'):?>
window.location.href = "/dab/profile";
<? else:?>
window.location.href = "/hq/edit_page";
<? endif;?>
});