<rss version="2.0">
		<channel>
			<title>Akelos PHP Framework Forum - [solved] How to get a Form&amp;#039;s Inputfield values for AkActionMailer?</title>
			<lastBuildDate>Mon, 06 Sep 2010 09:57:15 +0200</lastBuildDate>
			<link>http://forum.akelos.org/</link>
			<description></description>
			<generator>
				Lussumo Vanilla 1.1.4 &amp; Feed Publisher
			</generator>
			<item>
		<title>[solved] How to get a Form&#039;s Inputfield values for AkActionMailer?</title>
		<link>http://forum.akelos.org/discussion/843/?Focus=3319#Comment_3319</link>
		<guid isPermaLink="false">http://forum.akelos.org/discussion/843/?Focus=3319#Comment_3319</guid>
		<pubDate>Tue, 10 Nov 2009 22:41:14 +0100</pubDate>
		<author>Oliver</author>
		<description>
			<![CDATA[ <p>Hi everybody,</p>

<p>I am stuck with the AkActionMailer. I somehow miss something between gather the Form's inputfield-values and use them to send e-mails. I followed the instructions in the <a href="http://www.akelos.org/wiki/sending-e-mail">/lib/AkActionMailer.php</a>. Here is what I did:</p>

<pre><code>./script/generate mailer Notifier contactNotification
</code></pre>

<p>Then I changed <strong>/models/notifier.php</strong> to the following:</p>

<pre><code>class Notifier extends AkActionMailer
{

  function contactNotification($params)
  {
    $this-&gt;set(array(
        'recipients'    =&gt; 'mymail@host.com',
        'from'          =&gt; $params['email'],
        'subject'       =&gt; $params['subject'],
        'contentType'   =&gt; 'text/html',
        'body'          =&gt; array(   'Sender'        =&gt; $params['email'],
                            'Subject'       =&gt; $params['subject'],
                            'Message'       =&gt; $params['message']),
        'headers'       =&gt; array(   'MIME-Version'  =&gt; '1.0',
                            'Reply-To'      =&gt; $params['email'],
                            'X-Mailer'      =&gt; 'PHP/'.phpversion())
    ));
  }   
}
</code></pre>

<p>The <strong>/views/notifier/contactNotification.tpl</strong> look like this (but here I want to have all fields from the form available...):</p>

<pre><code>&lt;html&gt;
  &lt;body&gt;
    &lt;h1&gt;{$Subject} by {$Sender}&lt;/h1&gt;
    {$Message}
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>In my <strong>Application Controller</strong> I have:</p>

<pre><code>function submit()
{
    if (!empty($this-&gt;params['contact']['email']))
    {
        if (empty($this-&gt;params['contact']['message']))
        {
            $this-&gt;flash['error'] = $this-&gt;t('&lt;b&gt;No Message&lt;/b&gt; This is a required field.');

        } else {
            Ak::import_mailer('notifier');
    $Notifier = new Notifier();
    if ($Notifier-&gt;deliver('contactNotification', $this-&gt;params['contact']))
            {
                $this-&gt;flash['tip'] = $this-&gt;t('&lt;b&gt;Thank You!&lt;/b&gt; We received your message.');

            } else {

                $this-&gt;flash['error'] = $this-&gt;t('&lt;b&gt;An Error occured&lt;/b&gt; Please try again.');
            }
        }

    } else {

        $this-&gt;flash['error'] = $this-&gt;t('&lt;b&gt;No E-Mail&lt;/b&gt; We need this to contact you.');
    }

    $this-&gt;redirectTo('index');
}
</code></pre>

<p>And the <strong>HTML Form in the template</strong> looks like this:</p>

<pre><code>&lt;?php $contact_form = $form_helper-&gt;form_for('contact', $Contact, array('url' =&gt; array('action' =&gt; 'submit'))); ?&gt;
  &lt;b&gt;_{Name}&lt;/b&gt;        &lt;?= $contact_form-&gt;text_field('name'); ?&gt;&lt;br /&gt;
  &lt;b&gt;_{eMail}&lt;/b&gt;       &lt;?= $contact_form-&gt;text_field('email'); ?&gt;&lt;br /&gt;
  &lt;b&gt;_{Subject}&lt;/b&gt;     &lt;?= $form_options_helper-&gt;select('contact', 'subject', array('Contact me', 'Question', 'Information', 'General/Other')) ?&gt;&lt;br /&gt;
  &lt;b&gt;_{Message}&lt;/b&gt;     &lt;?= $contact_form-&gt;text_area('message') ?&gt;&lt;br /&gt;
  &lt;input type="submit" value="_{Send}" /&gt;
&lt;?= $contact_form-&gt;end_form_tag(); ?&gt;
</code></pre>

<p><strong>When I send the form (with valid data), I get the message</strong>: "Fatal error: Class 'Notifier' not found in /myproject/app/controllers/myproject_controller.php"</p>

<p>I think I have also some basic misunderstanding in handling this. How can I access the mailer model? Forbear with me, as I am just very new to Akelos.</p>

<p>Anyway, appreciate all your help,<br />
Oliver</p>
 ]]>
		</description>
	</item>
	<item>
		<title>[solved] How to get a Form&#039;s Inputfield values for AkActionMailer?</title>
		<link>http://forum.akelos.org/discussion/843/?Focus=3320#Comment_3320</link>
		<guid isPermaLink="false">http://forum.akelos.org/discussion/843/?Focus=3320#Comment_3320</guid>
		<pubDate>Tue, 10 Nov 2009 23:10:40 +0100</pubDate>
		<author>Oliver</author>
		<description>
			<![CDATA[ <p>Well, I guess you can forget it - looks like I was able to solve it thank to (this Discussion)[http://forum.akelos.org/discussion/527/] :)</p>

<p>I edited my initial post so it shows now the working code...</p>

<p>However, I'd appreciate any comments on the code above if there are thing I could to "better".</p>
 ]]>
		</description>
	</item>
	
		</channel>
	</rss>