Welcome, Guest
Username: Password: Remember me

TOPIC: Call function within fly page for each pivot item

Call function within fly page for each pivot item 28 Feb 2019 12:13 #15677

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
I have 2 tables, teams and students.
Then 2 pivot tables, turnups and teamstudents

On my teams item page, I’m listing the pivot table teamstudents. All of this is working.
Now I would like a button next to each student, and when clicked it should add data to the turnups table.

I’m a bit stuck here

My button looks like this
<td>
			<?php echo JDom::_('html.link', array(
			 'commandAcl' => array('core.edit.own', 'core.edit'),
			 'content' => 'Turnup',
			 'num' => $rel->id,
			 'task' => 'team.turnup'
			));?>
		</td>

Controller -> team.php
protected function turnup($data = array(), $key = id) {
		

	}

Model -> team.php
public function turnup($data) {
			
		
	}

I have tried to create a send mail in controller and model function, but nothing happens, so I’m guessing the functions are never really called. What I’m I missing?

Any help is appreciated.
Last Edit: 28 Feb 2019 12:30 by dyvel.
The administrator has disabled public write access.

Call function within fly page for each pivot item 14 Mar 2019 21:00 #15679

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Did you got sorted out ? since then ?
Coding is now a piece of cake
The administrator has disabled public write access.

Call function within fly page for each pivot item 02 Apr 2019 07:23 #15695

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
admin wrote:
Did you got sorted out ? since then ?

Almost, but not completely.
I have made my button look like this:
<a href="/index.php?option=com_cphdans&task=team.registerturnup&team=<?php echo $this->item->id; ?>&id=<?php echo $rel->id; ?>

This will trigger my team controller where I have a function called registerTurnup. This works.
But, my main issue now, is I'm redirected to a page without content instead of staying on the same page as the button.

I have tried a redirect back, but can't get HTTP_REFERER value in my controller function, so not sure how to solve that....

This is my function as of now:
$data = new stdClass();
		$data->student = JRequest::getInt('id',0);
		$data->team = JRequest::getInt('team',0);
		$data->date = date("Y-m-d H:i:s", strtotime("now"));
		
		$db 	= JFactory::getDbo();
		$sql = 'SELECT id FROM #__cphdans_turnups WHERE team = '.$data->team.' && student = '.$data->student.' && DATE(`date`) = CURDATE()';
		$db->setQuery($sql);
		
		// Brug loadResult() hvis der kun forventes en værdi
		$result =  $db->loadResult();
		
		if (!$result) { // insert timestamp			
			$result = JFactory::getDbo()->insertObject('#__cphdans_turnups', $data);
		}
		
		// TODO - GET THIS RIGHT...............................................................................................................
		
		// redirect user back to referring url
		$url = $_SERVER['HTTP_REFERER'];
		$this->setRedirect('/timeregistrering/team/team/391-hold-1'); // should be $url, but it is empty...
		
		// TODO - GET THIS RIGHT...............................................................................................................
The administrator has disabled public write access.

Call function within fly page for each pivot item 02 Apr 2019 07:29 #15696

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
BTW, the notification mail for your answer landed in my spam folder. Looked at the message headers and found this: Arc-Authentication-Results: ⁨i=1; mx.google.com; spf=softfail (google.com: domain of transitioning This email address is being protected from spambots. You need JavaScript enabled to view it. does not designate 2a01:7e00::f03c:91ff:febb:96e4 as permitted sender) smtp.mailfrom=support@j-cook.pro⁩

Looks like you need to add that IPV6 in your SPF DNS record
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Call function within fly page for each pivot item 09 Apr 2019 23:42 #15711

  • Nicolas
  • Nicolas's Avatar
  • Offline
  • Premium Member
  • Posts: 83
  • Thank you received: 12
  • Karma: 6
Hi Dyvel
why do not you do it in ajax if you have to stay on the same page? you make a call to your controller.yourTask to load or save datas. it's more fluid for the user and your server.
Last Edit: 10 Apr 2019 00:06 by Nicolas.
The administrator has disabled public write access.

Call function within fly page for each pivot item 09 Apr 2019 23:58 #15712

  • Nicolas
  • Nicolas's Avatar
  • Offline
  • Premium Member
  • Posts: 83
  • Thank you received: 12
  • Karma: 6
A note appart, you're using the deprecated JRequest::getInt(); where you should be using
$input = JFactory::getApplication()->input;
$country_id = $input->getInt('country_id', 0);
Last Edit: 10 Apr 2019 00:05 by Nicolas.
The administrator has disabled public write access.
The following user(s) said Thank You: dyvel

Call function within fly page for each pivot item 10 Apr 2019 05:59 #15713

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Nicolas wrote:
Hi Dyvel
why do not you do it in ajax if you have to stay on the same page? you make a call to your controller.yourTask to load or save datas. it's more fluid for the user and your server.

Hi Nicolas

AJAX would be a better solution, I agree.
But I'm not sure how I should do it with AJAX.
The administrator has disabled public write access.

Call function within fly page for each pivot item 10 Apr 2019 08:27 #15715

  • Nicolas
  • Nicolas's Avatar
  • Offline
  • Premium Member
  • Posts: 83
  • Thank you received: 12
  • Karma: 6
Hi
For your buton you can try something like
<a id="yourId" class="btn btn-info btn-default"><i class="icon-joomla icon-joomla"></i> <?php echo JText::_('IF_YOU_NEED_A_TEXT'); ?></a>

And i don't know how you wanna take your datas and how you wanna use these, but your can call an ajax.post like :
jQuery.ajax({
     url:'index.php?option=com_component&task=controller.task',
     type: "POST",
     data: {
           '<?php echo JSession::getFormToken()?>': =1,
           'student': yourStudentValue,
           'team': yourTeamValue
     },
     success: function(data){
          //Do something on sucess ans reload same page
          location.reload();
     }
})

hope this help

Nicolas
Last Edit: 10 Apr 2019 08:31 by Nicolas.
The administrator has disabled public write access.
The following user(s) said Thank You: dyvel

Call function within fly page for each pivot item 23 Apr 2019 07:09 #15723

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Hi Nicolas

Your post really helped me getting ajax posting to work. Thanks.
For reference, I ended up with this:
<script>
	function registerTurnup(student) {
				
		jQuery.ajax({
			url:'/index.php?option=com_cphdans&task=team.registerturnup',
			type: "POST",
			data: {
				'id': student,
				'team': <?php echo $this->item->id; ?>
			},
			success: function(data){
				location.reload();
			}
		})
		
	}
</script>

And my button:
<a onclick="registerTurnup(<?php echo $rel->id; ?>)" class="uk-button uk-button-primary uk-align-right uk-margin-bottom-remove"><?php echo JText::_('CPHDANS_FIELD_TURNUP'); ?></a>
The administrator has disabled public write access.

Call function within fly page for each pivot item 23 Apr 2019 12:49 #15725

  • Nicolas
  • Nicolas's Avatar
  • Offline
  • Premium Member
  • Posts: 83
  • Thank you received: 12
  • Karma: 6
Hi Dyvel
if everything works well it's great.
Thank you for sharing
I hope it will help other cooks
The administrator has disabled public write access.
Time to create page: 0.098 seconds

Get Started