You can use json for this, I will create an example.
It has some non-forkable code, because you need a controller.json.php, which is not generated by Cook but has to be in controllers folder in order to work.
I will assume some names in the code, you will probably have to change it and there will also be some typos
First: create a bids.json.php file in the controllers folder (site) of your component (I will assume com_bids)
Then paste this code
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
class BidsCkControllerBids extends BidsClassControllerList
{
public function createbid() {
try
{
//you can get inputs from the calling code:
//$var1 = JFactory::getApplication()->input->get('var1','','string'));
//$var2 = (int)JFactory::getApplication()->input->get('var2,0,'int'));
$data = array();
$table = JTable::getInstance('bid', 'BidsTable');
//set your properties
$table->created_by = (int)JFactory::getUser()->get('id');
$table->creation_date = XplogHelperDates::getSqlDate(date("Y-m-d H:i:s"), array('Y-m-d H:i:s'), true);
//etc.....
if ($table->check()) //you can create a custom check if you need it
{
if ($table->store())
{
$inserted_id = $table->getDBO()->insertid();
}
}
$step = 2; //or get some next step
$data["step"] = $step;
$data["bidID"] = $inserted_id;
echo new JResponseJson($data);
}
catch(Exception $e)
{
echo new JResponseJson($e);
}
}
}
// Load the fork
BidsHelper::loadFork(__FILE__);
// Fallback if no fork has been found
if (!class_exists('BidsControllerBids')){ class BidsControllerBids extends BidsCkControllerBids{} }
The code above will return {"success":true,"message":null,"messages":null,"data":{"step":2,"bidID":42}}
See also:
docs.joomla.org/JSON_Responses_with_JResponseJson
Next, fork the tpml file (you probably already did that and add javascript:
<script type="text/javascript">
function CreateBid() {
jQuery.ajax({
type:"POST",
url: "index.php?option=com_bids&task=bids.createbid&format=json",
//data: if you need it, can be something like 'var1='+encodeURIComponent(jQuery("#sometextfield").val())+"&var2="+somevar,
//you can use that in the conroller!
success: function(r){
//debug, check the result
console.log(r);
if (r.data) {
//you will have data as an object.
//you can use r.data.step and r.data.bidID
}
}
});
}
</script>
Make your button
<button onclick="return CreateBid();" class="btn btn-success">Start Bid</button>
When clicking the Start Bid button, you will call the CreateBid() function.
The will do an ajax post to the controller and return data. You can then use that data for further coding
Maybe call a function GotoStep(r.data.step) or someting like that.