1

I have this simple search form inside a custom module.

HTML FORM:

<div id="search-form">
<form action="" method="post">
<input type="text" name="roll_no">
<input type="submit" name="submit">
</form>
</div>

PHP:

if(isset($_POST['submit']))
{

// getting text from HTML text box

$roll_no = $_POST['roll_no'];

// executing MySql query to fetch a particular record

$query = $db->getQuery(true);
$query->select('name')
       ->from($db->quoteName('students'))
       ->where($db->quoteName('student_id') . " = " . $db->quote($roll_no));

$db->setQuery($query);
$result = $db->loadResult();
$row = $db->loadrow();

echo $row['0'];

}

It works perfectly, but it refreshes the whole page. Can I somehow make it only refresh that particular module (div element).

Help would be appreciated.

2

To achieve what you want, you can not submit the form.

You have to use an ajax call.

see jQuery.ajax documentation

Get a response and modify the DOM in order to reflect that response.

There is a nice example how to do it here:

https://www.ostraining.com/blog/joomla/search-ajax/

2
  • I have no experience with AJAX, can you explain it with some code?
    – saibbyweb
    Sep 20 '16 at 7:01
  • I edited the answer to add a place with an example Sep 20 '16 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.