Page 1 of 1

PostPosted: Thu May 18, 2006 6:45 am
by shiraz
Hiya,

I've built an extra action into "action to be performed" which looks at the current record set and extracts the email addresses from them. The idea is to be able to email everyone that matches a particular search criteria. That took me a while but I got it.

So now I have a list of email addresses and I want to create a form for the Dataface user to fill out, and then everyone that was on the list will get emailed the contents of the form. Basically, a mailing list system. I'm able to pass the email addresses over, that's no problem.

The problem I'm having is with the form. Generating it has been easy. But actually getting the results out of it has been hard. I've tried two approaches, both of which initiate within my custom function in ResultList.php, called toHtml_email(), which is used in place of toHtml() for my custom action:

1. My first approach was to include the form -- include ('/home/trini6/public_html/database/mailform.php') -- which appears just before ob_start(). In the mailform I used a straight-ahead HTML quickform code as follows:

addElement('text','title','Book Title:');
// Add a select box
$subjects = array('Math','Ice Fishing','Anatomy');
$form->addElement('select','subject','Subject(s): ',$subjects);
// Add a submit button
$form->addElement('submit','save','Save Book');
// Add a validation rule: title is required
$form->addRule('title','Please Enter a Book Title','required');
// Call the processing function if the submitted form
// data is valid; otherwise, display the form
if ($form->validate()) {
$form->process('praise_book');
} else {
$form->display();
}
// Define a function to process the form data
function praise_book($v) {
global $subjects;
// Entity-encode any special characters in $v['title']
$v['title'] = htmlentities($v['title']);
print "$v[title] is a great book about ";
print $subjects[$v['subject']] . '.';
}
?>


2. The second approach I used was to copy SearchForm.php to mailform2.php, rename the class, and then modify the methods in it to my own end. I instantiate the object as follows:

require_once '/home/trini6/public_html/database/mailform2.php';
$form =& new Shiraz_MailForm($this->_tablename, $this->_db, $this->_query);

In both cases the problem I'm having is once I hit the form submit button, Dataface reloads the table. ie. no validation, and moreover I do not know where/if the variables are actually being stored. Basically I just want to know how to validate the form, and how to retrieve the data that is submitted. I'm unclear on the principals.

I thought I'd put it on here because I know it's probably really simple.


Happy Friday,

Shiraz

PostPosted: Thu May 18, 2006 10:06 am
by shannah
Hi Shiraz,

In order for your form to be processed you have to pass the "-table" and "-action" flags (or at least the "-action" flag as a hidden field so that Dataface will know which action is being performed and can pass control back to your custom script upon submission.

something like:

Code: Select all
$form->addElement('hidden', '-action');
$form->setDefaults( array('-action'=>$_REQUEST['-action']));


Hope this helps

PostPosted: Tue May 30, 2006 10:49 am
by shiraz
Yes, that did end up helping. Thanks Steve.