jQuery fancybox post - php

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;
});

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.

Having issues sending upload values to hidden field

i have been trying so hard to fix my issue. I've looked on google loads and attempted the fixes but i am having no luck at all.
$(function() {
$("#listing_pic").uploadify({
height : 30,
swf : 'uploadify/uploadify.swf',
uploader : 'uploadify/uploadify.php',
width : 120,
fileExt : '*.jpg; *.jpeg; *.JPG; *.JPEG;',
checkExisting : 'uploadify/check-exists.php',
simUploadLimit: 2,
fileSizeLimit : '4MB',
auto : true,
multi : true,
onComplete : function(event,queueID,fileObj,response,data) {
$('#hiddenlistingpic').val(response);
},
});
});
Im trying to get Uploadify to upload my image to my server (which works fine) but then send the filename to the hidden field so that i can post the data into my database update class. It's giving me a headache, and im more than certain its a simple fix.
from here: https://stackoverflow.com/a/3466188/1253747
$(function() {
$("#listing_pic").uploadify({
height : 30,
swf : 'uploadify/uploadify.swf',
uploader : 'uploadify/uploadify.php',
width : 120,
fileExt : '*.jpg; *.jpeg; *.JPG; *.JPEG;',
checkExisting : 'uploadify/check-exists.php',
simUploadLimit: 2,
fileSizeLimit : '4MB',
auto : true,
multi : true,
onComplete : function(event,queueID,fileObj,response,data) {
$('#hiddenlistingpic').val(fileObj.name);
},
});
});
or from the uploadify docs, there seems to be many other ways to get it:
'onUploadSuccess' : function(file, data, response) {
$('#hiddenlistingpic').val(file.name);
}
same thing can be done with the onuploadcomplete.
or is there anything else that i am missing?

How to load php page with fancybox? [closed]

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;
});

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