Netbeans - Syntax Check error using php inside javascript - netbeans

Netbeans 7.0 is highlighting lines as syntax error when i use PHP inside JavaScript
In my case
<script type="text/javascript">
$(document).ready(function(){
$("#rating_<?=$coObj->company_id?>").jRating({
step: true,
longStarsPath:"include/jrating/jquery/icons/btn_black_trans2.png",
rateMax:1,
phpPath:"include/jrating/php/jRating.php",
<?php
if($_SESSION["rate_of_".$coObj->company_id] == 1)
echo 'isDisabled: true,';
else
echo 'isDisabled: false,';
?>
type:'long',
length : 1,
decimalLength : 0,
rateMax: 1,
onSuccess : function(){
alert('Success : your rating has been saved');
location.reload(true);
},
onError : function(){
alert('Error : please retry');
}
});
});
</script>
all the lines below PHP code are highlighted, and first line says that missing : after property id

#Marek:
I don't really see that as an answer, more of a workaround (which doesn't always work)...
NetBeans should make things easier, not make us change syntax to avoid it failing in the highlighting...
Anyways, I use a lot of mixed Javascript/PHP code, and NetBeans fails miserably all over the place...I also use Notepad++ which doesn't have any problems with this...
Example:
function showUpload<?php echo $upload_number;?>(file) { /*some code*/ }
Or:
$('.option-help').qtip({
content: function(api) { return $(this).parent().attr('data-tip'); },
<?php if ($option_help == 'icon') { ?>
show: { event: 'click' },
<?php } ?>
position: {my: 'bottom left',at: 'top left'}
});
Does anyone know of a better solution to the OP's question?!?

edit your syntax to this:
isDisabled:<?php
if($_SESSION["rate_of_".$coObj->company_id] == 1)
echo 'true';
else
echo 'false';
?>,

Related

codeigniter form_validation with ajax

When i submit it with no data, it shows like this. but i want it to show on my modal, because i'm using the form_validation library.
enter image description here
This is my Controller:
$this->form_validation->set_rules('category_name','Category name','trim|required');
if($this->form_validation->run() == FALSE){
echo validation_errors();
} else{
$category = array(
"category_name" => $this->input->post('category_name')
);
$this->category_m->insert($category);
echo "Successfully Added.";
}
This is my ajax file:
$(document).on('submit', '#form' ,function(event){
event.preventDefault();
var form = $(this).serialize();
$.ajax({
url:"<?php echo base_url(); ?>category/operation",
type:"POST",
data:form,
success:function(data){
$('#form')[0].reset();
$('#mymodal').modal('hide');
$('#alert').fadeIn().html('<div class="alert alert-info">'+data+'</div>').fadeOut(5000);
table.ajax.reload();
}
})
});
This is not related to Codeigniter. It's JS/jQuery/HTML/...
Assuming that you have something like this in your HTML
<div id="mymodal">...</div>
Create another div#alert inside
<div id="alert">...</div>
And change the Javascript to something like
//You don't neet fadeIn/fadeOut
$('#alert').html('<div class="alert alert-info">'+data+'</div>');
$('#mymodal').modal('show');

fancybox code delay on opening

I have the following code
jQuery(document).ready(function() {
jQuery("#popup-form-signin").fancybox({
'showCloseButton' : false,
});
<?php if (!isset($_SESSION['popup_subscribe'])) :
$_SESSION['popup_subscribe'] = 1;
?>
jQuery("#popup-form-subscribe").fancybox({
'closeClick' : false,
}).click();
setTimeout(function(){
jQuery("#popup-form-subscribe").click();
}, 20000);
<?php endif; ?>
I need to add a timeout to delay the popup
i found the code
setTimeout( function() {$('#popup-form-subscribe').trigger('click'); },20000);
but i dont know where to put it
I think you just have to remove ".click()" when initialising fancyBox, e.g.:
jQuery("#popup-form-subscribe").fancybox({
'closeClick' : false,
});
setTimeout(function(){
jQuery("#popup-form-subscribe").trigger('click');
}, 20000);

Wordpress and Facebook php sdk 4.0

I have wordpress 4.1 with the following plugin installed:
iThemes Security
WordPress SEO
I plugged in a function the facebook sdk.
This is the code:
//Footer
add_action('wp_footer', 'my_footer');
function my_footer() {
$post_to_check = get_post(get_the_ID());
if ( is_singular() && has_shortcode( $post_to_check->post_content, 'myshortcode' ) ) {
?>
<script>
var DEBUG = true;
jQuery(document).ready(function($){
$.ajax({
type : "POST",
url : "index.php",
data : { action : "value" },
success : function(response){
// the server has finished executing PHP and has returned something, so display it!
if(DEBUG){ console.log('AJAX done...'); }
}
});
});
</script>
<?php
}
}
//ajax
add_action('init', 'my_request');
function my_request() {
if ( isset($_POST['action']) && $_POST['action'] == 'value' ) {
session_start();
require_once __DIR__ . "/sdk/autoload.php";
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookSDKException;
$app_id = getAppId();
$app_secret = getAppSecret();
$rdr_fb_url = curPageURL();
$required_scope = 'public_profile, email';
if(empty($app_id) || empty($app_secret))
exit('Error.');
FacebookSession::setDefaultApplication($app_id , $app_secret);
$helper = new FacebookRedirectLoginHelper($rdr_fb_url);
try {
$session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
die(" Error : " . $ex->getMessage());
} catch(\Exception $ex) {
// When validation fails or other local issues
die(" Error : " . $ex->getMessage());
}
var_dump($session);
if ($session){
$user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
echo 'Hi'.$user_profile->getName();
}else{
//display login url
$login_url = $helper->getLoginUrl( array( 'scope' => $required_scope ) );
}
?>
<div class="login">
Login
</div>
<?php
exit();
}
}
Works fine if i use this outside of wordpress.
In wp var_dump($session); retrive always null. (no error given) Even after accepting the terms of the application. it is as if he could not get the code in the url.
I also tried to disable the plugin, but nothing.
I need php, please don't tell me to use javascript.
Sorry for my bad english :P
Edit:
I use the permalink:
http://www.myste.com/%year%/%monthnum%/%postname%/
I think the problem is the rewrite rule that hide a facebook get.
Solved: I entered the code outside of the ajax call, in function my_footer() {

laravel 4 changing url structure with parameter passing

I'm just a beginner in laravel framework. i created a simple form and controller methods . i think by default the form method is post. but now i need to make it as get method and also wants to pass the selected inputs to controller and shows that parameters in the url also. currently i did like below but failed.
index.blade.php
<?php echo Form::open(array('url' => 'home/find','method' => 'get')); ?>
<select class="location" id="location" name='location'>
<?php
$id1 = /* get user db details based on locations*/
$location_id_drop_down='';
foreach($idl as $lrow)
{
$city_name=Location::where('location_id','=',$lrow['loc_id'])->first();
if($city_name==array()) continue;
if(Input::old('location')==$lrow['loc_id'])
{
$location_id_drop_down.="<option value='" . $city_name['location_name'] . "' selected='selected'>" .$city_name['location_name'] . "</option>";
}
else
{
$location_id_drop_down.="<option value='" . $city_name['location_name'] . "'>" . $city_name['location_name']. "</option>";
}
}
echo $location_id_drop_down;
?>
</select>
<input type="submit" name="search" id="search_submit" class="search_submit" value="Search" />
{{ Form::close() }}
HomeController.php
public function anyFind($s='',$d='',$l='') {
if(Input::get('search'))
{
$location=Input::get('location');
}
else
{
if($l!='~')
$location=$l;
}
/* queries to get the user details and images based on selected location and list them*/
}
Routes.php
Route::get('/find/{location}','HomeController#anySearch');
But this shows the url as mysite.com/home/find?location=Test&search=Search
I need mysite.com/home/find/location
is there any mistake in my code?
Edit
As a part of experiment i tried this method. i gave a redirect like below at the end of my controller function anyfind()
return Redirect::to('/home/find/'.$location);
But this redirects me but did anyone knows how to load the search.search_new.blade.php with this custom url??
Having a field from the form in your url (not query string) is simply not possible with Laravel. What you can do though, is just use javascript for that.
First lets put a placeholder in the action url
<?php echo Form::open(array('url' => 'home/find/%location%','method' => 'get')); ?>
jQuery
$('form').on('submit', function(){ // you maybe need to be a bit more precise with the selector here
var location = $('#location').val();
$(this).prop('action', $(this).prop('action').replace('%location%', location));
});
Vanilla Javascript (if you can't / don't want to use jQuery)
document.getElementsByTagName('form')[0].onsubmit = function(e){
var location = document.getElementById('location').value;
e.target.setAttribute('action', e.target.getAttribute('action').replace('%location%', location));
};
By the way: the code in your question has still some weird stuff in there. I'm just assuming this has happened because of copy paste etc. So if it still doesn't work, make sure you post the correct code
Insert at the end of your method anyFind() inside the HomeController.php where you set the view for the page:
if (Input::get('location') != '') {
return Redirect::route('home.findByLocation',Input::get('location'));
}
return View::make('home', compact('location));
Also in your routes.php add the following code:
Route::get('home/find/{location?}', array('as'=>'home.findByLocation', 'uses'=>'HomeController#anyFind'));

How to use Facebook FBJS Feed Forms

I'm trying to call a Feed Form in my Facebook application and I'm not sure how to do so. I'm not familiar with the FBJS and its API. Specifically I need the following dialogue to show up: http://wiki.developers.facebook.com/index.php/Feed_Forms
Here's what I got for now:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
return attachment;
Facebook.streamPublish(<?php echo $message; ?>, attachment, null, <?php echo $user; ?>);
</script>
Is there anything else I need to do in order to properly call a Feed form? A code example would help me a lot if anyone is willing to write one up.
Here's an example I use from a Facebook Connect site that I operate:
var message = 'This is my message!';
var attachment = {
'name':'Page name',
'href':'http://mysite.com',
'caption':'Some kind of caption';
};
attachment.media = [{'type':'image','src':'http://mysite.com/images/lolcat.jpg','href':'http://mysite.com'}];
var action_links = [{'text':'Action Link!','href':'http://mysite.com'}];
FB.Connect.streamPublish(message, attachment, action_links);
The FB.Connect methods are almost identical to the normal JS methods, so something similar should be working for you.
I would point out that you have <?php echo $message; ?> as the first parameter to your Facebook.streamPublish() call. Assuming $message is a text string, then you need to wrap that output in quotes in order for it to be valid Javascript. As well, the return attachment; line doesn't make much sense to me. Why is there a return statement there? I would change your code to this:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
Facebook.streamPublish('<?php echo addslashes($message); ?>', attachment, null, <?php echo $user; ?>);
</script>
For FBML canvas pages, all you need to do is execute the command as follows:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
Facebook.streamPublish('', attachment, null);
</script>
That should easily bring up the Feed Form.