Jump to content

Recommended Posts

Hiya peeps!

 

In my index page I have a search box that submits to search.php,

 

This is the code I am using in search.

 

<?php session_start();
include 'system/core/template.php';
$template = new template();

if(isset($_POST['keyword'])):
$js = 'alert(\'LOL\');
var key = "' . $_POST['keyword'] . '";
  $.post("system/core/switchboard.php?cmd=search", { key: key }, 
                function(data) {
	$("span#search").html(data);
	});
	return false;
		});';
endif;

$parts = array('TITLE' => 'Search',
		   'CONTAINERTWOTITLE' => '',
		   'CONTAINERTWOCONTENT' =>  '',
		   'CONTAINERTHREETITLE' => '',
		   'CONTAINERTHREECONTENT' => '',
		   'CONTAINERONETITLE' => 'Search Results.',
		   'CONTAINERONECONTENT' => '<span id="search"></span>',
		   'JQUERY' => '' . $js . ' 
		   $("form#search").submit(function(){

            var key = $("input#keyword").val();
	$.post("system/core/switchboard.php?cmd=search", { key: key }, 
                function(data) {
	$("span#search").html(data);
	});
	return false;
		});',
		   'INCLUDES' => '<script language="javascript" type="text/javascript" src="assets/js/paginate.js"></script>
			<script language="javascript" type="text/javascript" src="assets/js/tablesort.js"></script>',
		   'IECSS' => 'ul.fdtablePaginater {display:inline-block;}
ul.fdtablePaginater {display:inline;}
ul.fdtablePaginater li {float:left;}
ul.fdtablePaginater {text-align:center;}
table { border-bottom:1px solid #C1DAD7; }');
$template->load($parts);
?>

 

The source code is containg all the correct data but, as you can see I have an alert() this is not working nor is the post.

 

I dont understand why. Anyone got any ideas?

 

Many thanks

 

James.

Link to comment
https://forums.phpfreaks.com/topic/194263-if-echo-not-working/
Share on other sites

Definitely not a guru; however...

 

Shouldn't the IF line have an opening brace rather than a colon? Also is the $js line missing an apostrophe?

 

Like I said no guru here, just seemd strange.

 

Hiya bud,

 

Thanks for the reply mate, the its PHP 5.0 so instead of having this...

 

if(continue) {

}else{

}

 

You have...

 

if(continue):

else:

endif;

 

And nah :) all it prints ok, but there is no action being made, LOL.

 

Many thanks

 

James.

Link to comment
https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1021998
Share on other sites

is your form able to post to that page?

so before your conditional place:

echo '<pre>';
print_r($_POST);
exit('debug post');

 

do you see your form data in there??

 

Another thing to test is the alert, try adding it to the template js statically just to test that you can set the alert like that.

 

 

Just to set the record, the colon used in place of the curly brace is not specific to php5. It is just an alternate way to write the control structures. Typically this alternative syntax is helpful for front end developers so you'll see it in view logic that designers and UI developers will potentially be working in.

 

Reference: [http://theserverpages.com/php/manual/en/control-structures.alternative-syntax.php]

Link to comment
https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022152
Share on other sites

Definitely not a guru; however...

 

Shouldn't the IF line have an opening brace rather than a colon? Also is the $js line missing an apostrophe?

 

Like I said no guru here, just seemd strange.

 

Hiya bud,

 

Thanks for the reply mate, the its PHP 5.0 so instead of having this...

 

if(continue) {

}else{

}

 

You have...

 

if(continue):

else:

endif;

 

And nah :) all it prints ok, but there is no action being made, LOL.

 

Many thanks

 

James.

 

This has nothing to do with php5 and can be used in any version of php as an alternative syntax. Its not common in the business layer but allot of people use this alternate syntax in there view layer.

Link to comment
https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022157
Share on other sites

Definitely not a guru; however...

 

Shouldn't the IF line have an opening brace rather than a colon? Also is the $js line missing an apostrophe?

 

Like I said no guru here, just seemd strange.

 

Hiya bud,

 

Thanks for the reply mate, the its PHP 5.0 so instead of having this...

 

if(continue) {

}else{

}

 

You have...

 

if(continue):

else:

endif;

 

And nah :) all it prints ok, but there is no action being made, LOL.

 

Many thanks

 

James.

 

This has nothing to do with php5 and can be used in any version of php as an alternative syntax. Its not common in the business layer but allot of people use this alternate syntax in there view layer.

 

Oh my bad, LOL. Sorry. I like this version better, I think it is more easier to read.

 

Many thanks

 

James.

Link to comment
https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022160
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.