Welcome Guest, Not a member yet? Register   Sign In
simple search form --- desperately need help
#1

[eluser]Unknown[/eluser]
Appologies in advance. I really need some help with a very simple search form which for the life of me I can not get to work.

I want to ask the user for a certificate number ......

say it is '12345678'

I can not find an example anywhere that shows me how to search for the input'ed value pass it on to the controller and view the results, god knows I have looked everywhere!. I know it am missing something really simple but for the life of me I can not spot the issue.

My Form looks like this

<html>
<head>
<title>Find a Certificate Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body>
<?php echo validation_errors(); ?>
<?php echo form_open('certsfound'); ?>

<p>Certificate Number</p>
&lt;input type='text' name='searchstring' value="" size="50" /&gt;

<p>&lt;input type="submit" value="Submit" /&gt;&lt;/p>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


Not laugh .... but my controller looks like

&lt;?php
class Find extends Controller {


function index()
{

$this->load->view('findcert');
}




function getAll() {
$this->db->select('id', 'cert_number', 'orig_timestamp');
$this->db->from('cins_cert_numbers');
$this->db->where('cert_number', 'searchstring');
$this->load->view('certsfound');
$q = $this->db->get();

if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}

}
}



the resulting view is certsfound.php

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title>
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;/head&gt;

&lt;body&gt;
<div id="container">
<h1>List of Programs</h1>

&lt;?php foreach($rows as $r) : ?&gt;
<p>&lt;?php echo $r->id; ?&gt;</p>
<p>&lt;?php echo $r->cert_number; ?&gt;</p>
<p>&lt;?php echo $r->orig_timestamp; ?&gt;</p>

&lt;?php endforeach; ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;


Forgive my ignorance, I believe that I am not passing the submit value user enters 'searchstring' correctly

cheers
Bruce
#2

[eluser]jcavard[/eluser]
I am not sure I get your question correctly, but if you want to access the form data within your controller, you should do this
Code:
$this->input->post('searchstring'); // this will return the value the user entered in the field 'searchstring'
#3

[eluser]kgill[/eluser]
Bruce, first things first - in the future use the code tags to post your code to the forum it makes it a lot easier to read for those of us trying to help you. Next, let's forget about CI for minute - how much experience do you have with just plain html forms? CI's form helper generates html for you but you still have to understand what it is you're generating.

The reason none of this is working is you're submitting it to something that doesn't exist. Pull up your webpage and view source you'll see the action attribute in form tag pointing at something like "your_host_name/index.php/certsfound".

That means you're submitting the form to a controller called certsfound - you named your controller Find, guess what should go in form_open() Next, you aren't calling a method so it's going to default to executing the index function which does one thing, loads your view without passing any data to it. If you wanted to specify a method to execute you'd tack that onto the controller in your form_open. So either you need to fix your index function to call to getAll and pass the data to the view or you submit your form to Find/getAll and fix getAll to load the view and pass the data to it. Either way what you've got right now are two disconnected pieces that need to come together to do something.

If you haven't already done so, go and watch the video tutorials - if you have, watch them again and follow along - those should give you a working example of how all this fits together.
#4

[eluser]Unknown[/eluser]
Thanks for the response ....

I will re-watch the videos .....

cheers
bruce




Theme © iAndrew 2016 - Forum software by © MyBB