How to load php page with fancybox? [closed] - php

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I searched a lot but I can't find an answer.
In my contact.php I have this code:
<a class="mailform" href="submit.php">Click</a>
I have this script, but it doesn't work:
$('.mailform').click(function() {
$.fancybox(
{
'autoDimensions' : false,
'width' : 350,
'height' : 'auto',
'transitionIn' : 'none',
'transitionOut' : 'none',
'ajax' : {
cache : false,
url : this.href
}
}
);
});
Can you help me please?

You need to return false to stop the link from following through
$('.mailform').click(function() {
var myUrl = $(this).attr('href');
$.fancybox(
{
'autoDimensions' : false,
'width' : 350,
'height' : 'auto',
'transitionIn' : 'none',
'transitionOut' : 'none',
'ajax' : {
cache : false,
url : myUrl
}
}
);
return false;
});

I suspect your problem here is related to the scope of the magic this variable. In your code, this is referring to the object literal that you have assigned to 'ajax':. In order to do what I think you are trying to do, you will need another temporary variable. By convention, we call the variable that. You also need to return false from your click handler, stop stop the browser from following the link in the main window.
$('.mailform').click(function() {
// Here, `this` refers to the <a> DOM element, so we create a copy of it
// and store it in `that`
var that = this;
$.fancybox({
// Now `this` refers to the object you are passing to fancybox()
'autoDimensions': false,
'width' : 350,
'height' : 'auto',
'transitionIn' : 'none',
'transitionOut' : 'none',
'ajax' : {
// Now `this` refers to the object you are assigning to 'ajax':
cache : false,
url : that.href // Use `that` instead of `this`
}
});
// We also need to return false, to stop the browser following the link
return false;
});

Related

Load PHP via Ajax in fancybox

The following code display a page loaded with ajax when the page is loaded. However, I don't know how to load PHP within the ajax file. Can anyone help please?
/* <![CDATA[ */
// call fancybox
function openFancy(){
setTimeout( function() {$('.fancybox').trigger('click'); },0);
}
// create cookie on button click
function dontShow(){
$.fancybox.close(); // optional
$.cookie('visited', 'yes', { expires: 30 }); // expiration in 30 days
}
$(document).ready(function() {
var visited = $.cookie('visited'); // create cookie 'visited' with no value
if (visited == 'yes') {
return false;
} else {
openFancy(); // cookie has no value so launch fancybox on page load
}
$('.fancybox').fancybox({
scrolling : 'no',
width : '100%',
fitToView : true,
closeBtn : false,
padding : 0,
margin : 20,
locked : false,
scrollOutside : false,
closeClick : false,
helpers : { overlay : {
closeClick: false,
locked: true},
}
});
}); // ready
/* ]]> */
Try this:
For the link (HTML)
<a id="fancybox_ajax" href="overlay.php"></a>
For the fancybox's setup:(JS)
$("#fancybox_ajax").fancybox({
scrolling : 'no',
width : '100%',
fitToView : true,
closeBtn : false,
padding : 0,
margin : 20,
locked : false,
scrollOutside : false,
closeClick : false,
helpers : { overlay : {
closeClick: false,
locked: true},
},
//This is what you have to add
ajax : {
type : "POST",
//This is optional if you want to pass some data
data : 'key=value'
}
});
Good luck! ^^

I can not pass values to the uploadify scriptData

this is my code:
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : '../js/uploadify/uploadify.swf',
'uploader' : '../js/uploadify/uploadify.php',
'height' : '60',
'width' : '60',
'folder' : '../uploads/',
'muti' : true,
'displayData': 'speed',
'scriptData' : {'evento' : '<?php echo $galery['event'] ?>'},
});
});
I try to pass a value of a variable to the file uploadify.php where there will register these data in the database, but can not in any way ... I've tried looking at some papers but the result is the same ...
You can tray to create session_id() and pass to this value through by uploadify. Then call the session id from acton page. And match them.

Flexpaper in CodeIgniter

I am a newbie to CodeIgniter. I tried to use flexpaper in my CodeIgniter code using my PHP knowledge in the view area alone, and it doen't seem to be working. It stops with document loading....
I am trying to display already converted documents. My actual problem is this: in the below JavaScript code which is in the view area of my CI, addresses a location in the line SwfFile : escape(base) in the below code; now where should the folder which contains the swf files be placed?
var doc = '<?php print $doc; ?>';
var doc1 = '<?php print $doc1; ?>';
var base = 'swf/'+'<?php print $doc1; ?>';
var fp = new FlexPaperViewer(
'FlexPaperViewer',
'viewerPlaceHolder', { config : {
SwfFile : escape(base),
Scale : 0.6,
ZoomTransition : 'easeOut',
ZoomTime : 0.5,
ZoomInterval : 0.2,
FitPageOnLoad : true,
FitWidthOnLoad : true,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : false,
MinZoomSize : 0.2,
MaxZoomSize : 5,
SearchMatchAll : false,
InitViewMode : 'Portrait',
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: 'en_US'
}});
I think flash files in CI have to be in the root of the application to work.
To load your view files, you need to call:
$this->load->view('yourViewFile');
where in the view folder, the file name would be yourViewFile.php
In case if you haven't changed much in your codeigniter since after you downloaded it, this controller name should be welcome.php under application/controllers, and you can write the above code in your index() function!

jQuery fancybox post

I have a jQuery fancybox that takes the content from an iframe, here's the link to popup the box:
<a class="action_btn recommend_btn" act="recommend" href="recommend.php">Recommend</a>
and here's the code for the fancybox:
$(".action_btn").not(".save").click(function() {
$.fancybox({
'width' : 560,
'height' : 530,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'href' : $(this).attr('href')
});
return false;
});
now I would like to post something to this recommend.php, so I can use this attribute/value in recommend.php, how can I do this?
One way I can think of is to store a session in the page prior to hyperlinking, but doesn't seem right.. seems like there should be a better way to do this
You should still be able to use the _GET http variable I think so:
Click
Then in recommend.php use $_GET['some_variable']. Unless fancybox does something crazy with iFrames.
since you already are using jQuery and possibly want to do this on the fly use .post().
$(".action_btn").not(".save").click(function() {
$.fancybox({
'width' : 560,
'height' : 530,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'href' : $(this).attr('href')
});
// example uses a json object to pass data, change here to what you need.
// will also accept jQuery objects like so:
// $.post('recommend.php', $('#myData').serialize());
$.post('recommend.php', { name: 'John', time: '2pm' } );
return false;
});

javascript to php question

<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader' : 'scripts/uploadify.swf',
'script' : 'scripts/uploadify.php',
'buttonImg' : 'css/btn_browseFiles.png',
'rollover' : 'true',
'wmode' : 'transparent',
'height' : '26px',
'width' : '109px',
'cancelImg' : 'cancel.png',
'folder' : 'uploads',
'queueID' : 'fileQueue',
'simUploadLimit' : '2',
'auto' : true,
'multi' : true,
'onComplete' : function(event, queueID, fileObj, response, data) {
$('#filesUploaded').append('<li><strong>file:</strong> '+fileName+'</li>');
}
});
});
</script>
I want to get the "+fileName+" to echo in PHP so I can pass it in a contact form.
<?php $que = ""; ?>` fill in the blanks
<input type="hidden" name="" value="<?php echo($que); ?>">
Besides doing the following, I don't know of a way to pass Javascript variables to PHP...
<script type="text/javascript>
location.href="thisPage.php?fileName=" + fileName;
</script>
And then you would use PHP to do:
<?PHP $que = $_GET["fileName"]; ?>
If you want to use the text in the filename variable, you will need to pass it to a server request somehow.
It can be done several ways:
cookie
getline variable/query string
post variable (put it in a form element)
If you just want to get it into a value on the current page, you should be able to use javascript to do it:
#('#id_of_element').val(filename);
This is assuming you are using jQuery.
This looks like some sort of uploading flash component. If it is uploading the file to your server, then you should be able to intercept the request and work with it from there.
$trigger('uploadifyComplete',ID,{
'name' : event.currentTarget.name,
'filePath' : getFolderPath() + '/' + event.currentTarget.name,
'size' : event.currentTarget.size,
'creationDate' : event.currentTarget.creationDate,
'modificationDate' : event.currentTarget.modificationDate,
'type' : event.currentTarget.type
},
can you see these?so you can use fileObj.name to get file name.

Categories