Jump to content

set checkbox value inside a table


ngrmm
 Share

Recommended Posts

I have a page with a table. Each table row has a page-reference field and a checkbox.
The Page sends emails to all users (page-refrence->email-field) and change the value of the checkbox in a row to 1.

It works with this:

<?php

	// event ID fron url query
	$eventID = $input->get('eventID','int');

	// get event-page
	$event = $pages->get($eventID);

	// config
	$fromEmail = $event->event_mail_from;
	$fromName = $event->event_mail_from_name;
	$emailSubject = $event->event_subject;

	// email html body
	ob_start();
	include('./_inc/emailbody.inc');
	$emailBody = ob_get_clean();

	// make event-page editable
	$event->of(false); 

	// loop through table and send out emails
	foreach($event->event_clients_list as $event_table_row) {
		
		// get client page
		$clientPage = $event_table_row->client_name;
      
      	// get client email
		$clientEmail = $clientPage->email;
		
		// if client isn't invited yet (checkbox not checked)
		if($event_table_row->client_invited == '') {

			// send email
			$m = new WireMail();
			$m->to($clientEmail);
			$m->from($fromEmail, $fromName);
			$m->subject($emailSubject);
			$m->bodyHTML($emailBody);
			$m->send();

			// mark client as invited
			$event_table_row->client_invited = 1;
			$event->save('event_clients_list');	
		}
	}
?>

But i have to use a variable in my emailbody.inc which i'm able to get in the table-loop.
So i do the including of the body inside my loop. But this doesn't work anymore. Page sends out the emails but is unable to change the value of the checkbox.
I get no errors!
I'm using ProTable

<?php

	// event ID fron url query
	$eventID = $input->get('eventID','int');

	// get event-page
	$event = $pages->get($eventID);

	// config
	$fromEmail = $event->event_mail_from;
	$fromName = $event->event_mail_from_name;
	$emailSubject = $event->event_subject;

	// loop through table and send out emails
	foreach($event->event_clients_list as $event_table_row) {
		
		// get client page
		$clientPage = $event_table_row->client_name;
      
      	// get client email
		$clientEmail = $clientPage->email;

		// email html body
		ob_start();
		include('./_inc/emailbody.inc');
		$emailBody = ob_get_clean();

		// make event-page editable
		$event->of(false); 
  
		// if client isn't invited yet (checkbox not checked)
		if($event_table_row->client_invited == '') {

			// send email
			$m = new WireMail();
			$m->to($clientEmail);
			$m->from($fromEmail, $fromName);
			$m->subject($emailSubject);
			$m->bodyHTML($emailBody);
			$m->send();

			// mark client as invited
			$event_table_row->client_invited = 1;
			$event->save('event_clients_list');	
		}
	}
?>

 

Link to comment
Share on other sites

Got it working by using two loops. One for sending out emails and the other for changing the value.
 

	
	
	// loop through table and send out emails
	foreach($event->event_clients_list as $event_table_row) {
		
		// get client page
		$clientPage = $event_table_row->client_name;
      
      	// get client email
		$clientEmail = $clientPage->email;

		// email html body
		ob_start();
		include('./_inc/emailbody.inc');
		$emailBody = ob_get_clean();

		if($event_table_row->client_invited == '') {

			// send email
			$m = new WireMail();
			$m->to($clientEmail);
			$m->from($fromEmail, $fromName);
			$m->subject($emailSubject);
			$m->bodyHTML($emailBody);
			$m->send();		

		}
	}

	// make event-page editable
	$event->of(false); 
	
	// loop through table and change value
	foreach($event->event_clients_list as $event_table_row) {

		// if client isn't invited yet (checkbox not checked)
		if($event_table_row->client_invited == '') {
			$event_table_row->client_invited = 1;
			$event->save('event_clients_list');	
		}
		
	}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...