I'm having a problem with a TinyMCE plugin using long GET parameters. On my development server, the plugin works just fine. However, on the production server, the parameter is ignored.
The plugin is SMImage, it uses parameters like this one:
40a6ff4a9832c3e3f8e2fed4d50dc8c6cc42409476b487da936f60cf315f57ccc39c7629d4146097ade572cdf409083257eb2d6edbff7b46556efafd07d4802521d17e14d1021baeac712f8ee83be1f768f14f849e58edb37c8fcd9a8e61e5235a1bb885b0dd1c5b85a2642f22fba99d304a6f988795e1c2b088b8f80e7acc69bc0cea7f763320a6611bd24bc924e0e1bda887990f560cbbd9e1608545fd69859a1808286a263d4754b8b1f6a713c9bdaaa015649b92db2701b005bd91e6827ff4bde6b48bcb0e5ca509f568684c51a803dbc7f896cdfdbcd0cfafc202e20d68f45cdfe86b033f36ff05a0f52cc6381231682d20d3038fc4fe7aba0916c614e89ff2b64c6b6bae0b548f
Which is kinda long, but shouldn't be much of a problem (except on IE of course).
Under the production server, $_GET['get'] is not even defined, since it's ignored by PHP.
Is there a server setting that can be changed perhaps? Under PHP, what defines the maximum length?
I could use POST instead, but I'm not too sure how I could change this part of the plugin:
var get = 'id=1' + '&dir_root=' + ed.getParam('plugin_smimage_directory', '') + '&server=' + ed.getParam('plugin_smimage_server', '') + '&thumbnail_size=' + ed.getParam('plugin_smimage_thumbnail_size', '') + '&show_thumbnail=' + ed.getParam('plugin_smimage_show_thumbnail', '') + '&jpg_quality=' + ed.getParam('plugin_smimage_jpg_quality', '') + '&orderby=' + ed.getParam('plugin_smimage_orderby', '') + '&show_upload=' + ed.getParam('plugin_smimage_show_upload', '') + '&show_image_menu=' + ed.getParam('plugin_smimage_show_image_menu', '') + '&show_folder_menu=' + ed.getParam('plugin_smimage_show_folder_menu', '') + '&show_newfolder=' + ed.getParam('plugin_smimage_show_newfolder', '') + '&thumbnails_perpage=' + ed.getParam('plugin_smimage_thumbnails_perpage', '') + '&upload_filesize=' + ed.getParam('plugin_smimage_upload_filesize', '') + '&check_session_variable=' + ed.getParam('plugin_smimage_check_session_variable', '') + '&document_root=' + ed.getParam('plugin_smimage_document_root', '');
ed.windowManager.open({
file: url + '/index.php?get=' + SMImage_BinToHex(SMImage_RC4(get)),
width: ed.getParam('plugin_smimage_width', '800'),
height: ed.getParam('plugin_smimage_height', '500'),
inline: 1
},
{
plugin_url: url
})
Not sure if this is good idea, but you could try using cookie as workaround for passing that kind of parameters. In JS, before calling this window open, do smth like
document.cookie = 'SMImage_param=' + SMImage_BinToHex(SMImage_RC4(get))
and then call index.php without parameters. On server-side use
$_COOKIE['SMImage_param']
for getting this parameter value.
Of course, it will work only if PHP you are calling is on the same domain (but I'm almost sure that for your TinyMCE plugin it's there).
Related
I'll try to keep this simple and clear. I'm pretty new to using API's but I'm using the Flickr API to search for and display photos on my website based on a certain tag. For a simple, static web page this is quite simple and I've already got it working as intended. This is the jquery script I found to use:
$(function() {
var apiKey = 'MY_API_KEY_IS_IN_HERE';
var tag = '%23FFLIVE2014-09-03';
var perPage = '25';
var showOnPage = '6';
$.getJSON('http://api.flickr.com/services/rest/?format=json&method='+
'flickr.photos.search&api_key=' + apiKey +
'&tags=' + tag + '&per_page=' + perPage + '&jsoncallback=?',
function(data){
var classShown = 'class="lightbox"';
var classHidden = 'class="lightbox hidden"';
$.each(data.photos.photo, function(i, rPhoto){
var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/'
+ rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret;
var thumbPhotoURL = basePhotoURL + '_s.jpg';
var mediumPhotoURL = basePhotoURL + '.jpg';
var photoStringStart = '<a ';
var photoStringEnd = 'title="' + rPhoto.title + '" href="'+
mediumPhotoURL +'"><img src="' + thumbPhotoURL + '" alt="' +
rPhoto.title + '"/></a>;'
var photoString = (i < showOnPage) ?
photoStringStart + classShown + photoStringEnd :
photoStringStart + classHidden + photoStringEnd;
$(photoString).appendTo("#flickr");
});
$("a.lightbox").lightBox();
});
});
Create a #flickr div on a page and load that script, photos tagged #FFLIVE2014-09-03 would be displayed, if there are any. My problem is that the site/page I want to show the photos on is dynamic with data generated from a database. So website.com/page.php is the single page, in the database is data for a certain date and a performance that happened on it (For a band).
So what I'm struggling with is how to dynamically edit the tags searched for in the script. With the above script placed in my page.php obviously page.php?id=1 and page.php?id=261 will show the same photos, because the tags searched will be the same when in fact they should be different, based on the date for the data.
So, is there some way to do this? Generate the correct date tag to search for based on the database data? I can generate the correct tag inside the PHP file itself quite easily, just echo the first part of the tag then the date. But how would I do that in relation to the javascript? I gather it is possible to use PHP within Javascript but that would be outside the database, so it wouldn't know what it was generating.
I hope that makes sense!
Since I'm relativly new to the use of php and javascript I ran into this problem while trying to add multiple variables in a URL
I use the following script:
<script>
function refresh() {
var PCWDE = document.getElementById("PC");
var NMWDE = document.getElementById("naam");
var VNMWDE = document.getElementById("voornaam");
var ONDWDE = document.getElementById("onderneming");
var BTWWDE = document.getElementById("btwnummer");
var LNDWDE = document.getElementById("land");
this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value "&nm=" + NMWDE.value "&vnm=" + VNMWDE.value "&ond=" + ONDWDE.value "&btw=" + BTWWDE.value "&lnd=" + LNDWDE.value;
}
</script>
That's beeing activated trough the following html code:
<?php
$pc = $_GET['PCS'];
echo '<input type="text" name="pc" id="PC" onblur="refresh()" value="'.$pc.'">'
?>
The main reason for the use of this html code was that I needed to execute a query without submitting the form, while still beeing able to hold the value of the text box even when the page would refresh. The above html code is used multiple times with the use of different ID's.
The problem I face while trying to do this is that my code only works when only adding 1 variable to the URL like so:
this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value;
Otherwise it does not work. Either the 'onblur' event fails to work, or the script fails to run.
Is there a way to add the multiple variables to the URL in a similiar way to what i'm doing now?
You forgot plus signs. That's a syntax error and you should see the error message if you open the error console. (on firefox you press control-shift-j)
Shoule be:
this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value + "&nm=" + NMWDE.value + "&vnm=" + VNMWDE.value + "&ond=" + ONDWDE.value + "&btw=" + BTWWDE.value + "&lnd=" + LNDWDE.value;
I am submitting the form using jquery. Now i need to send form information into external server. The below is the part of my code that submit the form to another server. It works in all browsers except IE which gives me access denied error.
$.ajax({
url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
type:'POST',
data:"ID=" + $ID + "&Source=" + $Source + "¬ifyCc=" + $notifyCc + "¬ifyBcc=" + $notifyBcc + "&noMail=" + $noMail + "&CFirst=" + $first + "&CLast=" + $last + "&Phone=" + $Phone + "&Fax=" + $Fax + "&CEmail=" + $CEmail + "&Message=" + $message,
success: function() {
}
});
Any help?
You can not make an AJAX call to a different domain. See my answer here: jQuery ajax GET returns 405 Method Not Allowed
That being said if it truely works in other browsers then I'm assuming you're posting to the same domain. Then you have to look at the returned content. There should be no reason you'd get a 405 from IE but not from FF.
I suspect though that this doesn't work with other browsers either, because of the javascript security restrictions.
I have been working on a website that uses a combination of PHP, jQuery, MySQL and XHTML in order to register students for a piano recital. This has no official purpose other than a learning exercise for me in getting all of these to work together. However, I have had a lot of problems getting the PHP to talk with the database and I'm not sure what my problem is. But before that can be tackled there is a really annoying issue that I've run across. For some reason my jQuery is not building a complete post URL for the PHP.
I am using jQuery version: 1.4.2 from Google. The query string is being built by using:
var ajaxOpts = {
type: "post",
url: "../php/addRecital.php",
data: "&performance=" + $("#performanceType :selected").text() +
"&groupName=" + $("#groupName").val() +
"&student1fName=" + $("#firstName").val() +
"&student1lname=" + $("#lastName").val() +
"&student1id=" + $("#studentID").val() +
"&student2fname=" + $("#Second_Student_firstName").val() +
"&student2lname=" + $("#Second_Student_lastName").val() +
"&student2id=" + $("#Second_Student_studentID").val() +
"&skillSelect=" + $("#skillSelect :selected").text() +
"&instrument1=" + $("#instument1 :selected").text() +
"&otherInstrument1=" + $("#otherInstrument1").val() +
"&instrument2=" + $("#Instument2 :selected").text() +
"&otherInstrument2=" + $("#otherInstrument2").val() +
"&location=" + $("#locationSelect :selected").text() +
"&roomNumber=" + $("#roomNumber").val() +
"&time=" + $("#timeSlotSelect :selected").text()
,
success: function(data) { ...
There is more than the above function, but I didn't think that it would pertain to here. I then call the code using:
$.ajax(ajaxOpts);
However, instead of creating the entire query string I get:
http://sterrcs123.mezoka.com/schoolProject/assign/assign13.html?groupName=&firstName=Samuel&lastName=Terrazas&studentID=23-343-3434&Second_Student_firstName=&Second_Student_lastName=&Second_Student_studentID=&otherInstrument=&Second_Student_Instrument=&roomNumber=2
Which as you can tell is missing a number of keys and their values. I would appreciate any help I can get because this is really driving me insane. Thanks.
It appears that your form is simply submitting itself without using your AJAX operation. Did you attach to the form's submit event and THEN run your ajax call? You will also want to return false from the submit event handler to prevent the default behavior you are seeing above.
Example:
$('#formid').submit(function(){
//your ajax code here.
return false;
});
If you're talking to an ASP.Net web service then you would need data to be a JSON string of your arguments. Otherwise, you can pass your data in by using an object literal (truncated for brevity):
var ajaxOpts = {
type: "post",
url: "../php/addRecital.php",
data: {
performance: $("#performanceType :selected").text(),
groupName: $("#groupName").val(),
student1fName: $("#firstName").val(),
student1lname: $("#lastName").val()
},
success: function(data)
}
As per the missing values, make sure you're capturing the button click / form submit.
$('form').submit(function (e) {
$.ajax(ajaxOpts);
return false;
});
I've built one variable (horaires_lundi) in this file :
app/code/community/Unirgy/StoreLocator/controllers/Adminhtml/Locationcontroller.php
->setTitle($this->getRequest()->getParam('title'))
->setNotes($this->getRequest()->getParam('notes'))
->setStreetAddress($this->getRequest()->getParam('street_address'))
->setHorairesLundi($this->getRequest()->getParam('horaires_lundi'))
All variables are well displayed in JavaScript in this file :
app/design/frontend/default/default/template/unirgy/storelocator/map.phtml
(function(){
var storeLocator = new UnirgyStoreLocator({
mapEl: $('map'),
sidebarEl: $('sidebar'),
searchUrl: '<?php echo $this->getUrl('ustorelocator/location/search')?>',
generateSidebarHtml: function(m) {
return '<span style="font-size:14px; color:#C68804;"><b>' + m.title + '</b></span><br/>(Distance : ' + parseFloat(m.distance).toFixed(1) + ' ' + m.units + ')<br/>'
+ m.street_address + ' ' + m.test + ' ' + m.city + '<br/><b>' + m.notes + '</b><br/>';
},
generateMarkerHtml: function(m) {
var url = m.website_url.replace(/\s/,'');
var dataForm = new VarienForm('form-validate', true);
return '<span style="font-size:14px; color:#C68804;">' + m.title + '</span><br/>'
+ '<?php if (trim($this->getHorairesLundi())!=""): ?>Lun '+ m.horaires_lundi +'<?php else : ?>No horaire lundi<br/><?php endif; ?>'
variable m.horaires_lundi in JavaScript is well displayed in frontend.
But I can't make a condition in PHP to display m.horaires_lundi only if m.horaires_lundi exists...
Above I made a try with
<?php if (trim($this->getHorairesLundi())!=""): ?>
Is it a goog method? what else must I do?
Is there an other method with something like:
<?php if (Mage::helper(...
I've found a tutorial about Magento but can't find my solution.
There's a significant distinction between PHP and JavaScript: the former is a server-side scripting language, the latter a client-side scripting language. Though you can use PHP to conditionally echo JavaScript code to the browser (which I don't recommend), you can't access JavaScript variables in PHP. Just test for the presence of a JavaScript variable in the script itself.
If I understand your goal correctly, you can rewrite your last line of code to
return '<span style="font-size:14px; color:#C68804;">' + m.title + '</span><br/>' +
((m.horaires_lundi) ? 'Lun ' + m.horaires_lundi : 'No horaire lundi') + '<br/>';