Hard-coded Search Problem with 5.5

Permalink 1 user found helpful
Background: I've just downloaded Concrete5 and am building my first site and generally getting to know the system. I've searched the forums and what I've found there doesnt seem to work for me.

Instead of hardcoding a search form into the template as many posts have recommended I thought I would try replacing the content block in the Site Name stack with a HTML block containing the following:

<div><h1><a href="http://127.0.0.1/concrete5/index.php?cID=1"> Project Gryphon</a></h1> </div>
<div style="margin-right: 10px; margin-bottom: 10px; float:right" id="search">
<form class="mysearchform" method="get" action="<?php echo View::url('/search-results'); ?>">
<input type="text" name="query" class="whatever" />
<input type="submit" value="Go" class="something" />
</form>
</div>

Which effectively gives me the Site Name as it was plus a nicely aligned Search box in the same stack...and no need to edit source files...thus its maintainable from within the UI

However this doesnt work and gives the following error:

"The requested URL /concrete5/< was not found on this server."

The URL it is calling is "http://127.0.0.1/concrete5/%3C?query=cloud" where I enter cloud in the search box.

Can anyone assist me in getting this to work or let me know why it wont?

Thanks,
Alex

 
citytech2 replied on at Permalink Reply
citytech2
It is a silly try to implement a php code within a html block. The html block is just for html content or plain text. It doesn't support the php code indeed. By default there was a block called "search" which can help you to do this.

By the way, this community is pretty active. You can post your problems as many times as you will face.

Citytech
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
Your problem is that the code directly in the html block is executing out of context. You could do a whole load of convoluted stuff to try and get the context right, but that could easily lead to other side effects.

A much easier solution that is block based is to code the form you want into a custom template for the search block (rather than the page template you hinted at in the original post)
alsworld replied on at Permalink Reply
Do you mean copying the view.php file into /blocks/content/templates, editing that file and choosing that as the custom template for the content block embedded in the Site Name stack?
alsworld replied on at Permalink Reply
For anyone who is interested here is what I did that worked:

Copied /concrete/blocks/content/view.php to /blocks/content/templates/view2.php

Edited view2.php so that the original:
<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   $content = $controller->getContent();
   print $content;
?>

became this:
<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   $content = $controller->getContent();
   print $content;
?>
<div id="search-box" style="margin-right: 10px; float: right;">
<form action="<?php echo View::url('search-results'); ?>">
   <input type="text" id="search-keywords" name="query" value="Search" />
   <input type="submit" id="search-go" name="go" value="go"/>
</form>
</div>


and now i have a working search in the Site Name bar all nicely aligned and available on any page that uses that custom template for the Site Name stack.

Thanks to JohntheFish and ryan from this posthttp://www.concrete5.org/community/forums/customizing_c5/code-searc... for allowing me to understand how to make this work.