I am facing issue (as i am relatively new to Joomla Component Development) regarding how to pass values between two functions in a my Joomla Custom Component's controller.php
Below is my controller.php file
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
JHtml::script(Juri::base() . 'templates/googlemaps/navigation.js');
/**
* Hello World Component Controller
*/
class HelloWorldController extends JControllerLegacy
{
function display(){
echo '<form action="'. echo JRoute::_('index.php?option=com_helloworld&controller=helloworld&task=displayData') .'" method="post">';
echo '<h1>This is Insert Task</h1><br><input type="text" id="name" placeholder="Name"><br>';
echo '<input type="text" id="surname" value="surname" name="surname" placeholder="Surname">';
echo '<input type="submit" value="submit">';
echo '</form>';
}
function delete(){
$id=JRequest::getVar('id');
echo "You want to delete $id";
}
function displayData(){
$name=JRequest::getVar('name');
$surname=JRequest::getVar('surname');
//$mainframe =& JFactory::getApplication();
//$stateVar = $mainframe->getUserStateFromRequest( "$option.state_variable", "surname", "Hello" );
echo "Your name is $name and surname is $surname";
//**How can i get the name and surname variables here after the page refreshes and this task loads**
}
}
I have two form fields in the Display() task of controller and i want to get the values i enter in those fields in another task below named displayData(). The only way i figured out is using the post method of form and getting the variables via $_POST[ ] method. Joomla provides user state and variables and all that stuff but i m not able to figure out how to use them here.