jamesxg1 Posted March 5, 2010 Share Posted March 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/ Share on other sites More sharing options...
jamesxg1 Posted March 5, 2010 Author Share Posted March 5, 2010 Anyone see any problems with my logic or syntax ? Many thanks James. Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1021978 Share on other sites More sharing options...
litebearer Posted March 5, 2010 Share Posted March 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1021995 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2010 Author Share Posted March 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1021998 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2010 Author Share Posted March 5, 2010 B to the U to the M to the P . Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022006 Share on other sites More sharing options...
mikesta707 Posted March 5, 2010 Share Posted March 5, 2010 are you expecting the alert to happen when the if statement is true? if so maybe you should echo it so it actually gets written to the page an executed, rather than just storing it into a variable Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022121 Share on other sites More sharing options...
freakstyle Posted March 5, 2010 Share Posted March 5, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022152 Share on other sites More sharing options...
trq Posted March 5, 2010 Share Posted March 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022157 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2010 Author Share Posted March 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194263-if-echo-not-working/#findComment-1022160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.