Page 1 of 1

Send form email button

PostPosted: Mon Jul 30, 2012 7:02 am
by tomtom8
hello!
I need to submit a form after it is compiled to a specific email address by an email button
thanks

Michele

Re: Send form email button

PostPosted: Mon Jul 30, 2012 2:56 pm
by PolderBoy
Hello Michele,

The way I do this is:
Create a dummy column 'SentMail' in the table.
Make the record a enum with the value 'Yes','No'
You can put in the fields.ini
[SendMail]
widget:type=checkbox

In the tables/tablename.php create a function:

Code: Select all
function afterSave(&$record)
{
$app =& Dataface_Application::getInstance();
$respons =& Dataface_Application::getResponse();

   if ($record->val('SendMail') == 'Yes'))
      {
      if (mail($MailTo, $Subject, $Message , $headers) == True)
      {
                 $respons['--msg'] .= "\n --> Mail sent";
                 } else {
                 $respons['--msg'] .= "\n --> NO Mail sent";
                 }
                 }
}


That is how I do this, but a button would be nicer, I know.

With regards,
Brian

Re: Send form email button

PostPosted: Wed Aug 01, 2012 1:31 am
by tomtom8
Hello Brian thanks

I have a list of work orders, I need to send an email only when an order is changed and at the same fixed address.
I want to do this manually regardless of the conditions of the form itself
Michele

Re: Send form email button

PostPosted: Wed Aug 01, 2012 1:50 am
by PolderBoy
Hello Michele,

The user clicks the checkbox(sentmail) and saves the record.
So you use the checkbox as a botton.

if you always want to sent an email:
Then you can remove the if statement.
And you will recieve an email when save is clicked.
Code: Select all
function afterSave(&$record)
{
$app =& Dataface_Application::getInstance();
$respons =& Dataface_Application::getResponse();

      if (mail($MailTo, $Subject, $Message , $headers) == True)
      {
                 $respons['--msg'] .= "\n --> Mail sent";
      }
}


What you also can do is set a rss feed.
Then somebody will recieve an email when a record or groups of records are changed.

with regards,
Brian

Re: Send form email button

PostPosted: Fri Aug 03, 2012 10:04 am
by tomtom8
My need is not to send the email on the aftersave, but only as an option and a default address or on the fly address and not necessarily obtainable from a field. I inserted the following code on action.ini
Code: Select all
[email]
   label = "Email to"
   description = "Email to an address"
   order=11
   category=table_tabs
   condition="$query['-table'] == 'odl'"
   url = "{$this->url('????????????)}"
   permission=email

So I added the Send command, but do not know how to call the specific function of the form submission details of selected or current form.

I apologize for my not perfect English

With regards
Michele

Re: Send form email button

PostPosted: Fri Aug 03, 2012 12:57 pm
by PolderBoy
Hello Michele,

Can't help you there, but you could use a little bit of ajax.
In fields.ini you could:

widget:atts:onblur="SentMail();"
Maybe not 'onblur' but maybe onclick?

Or you could delve into the html files and hardcode the button in there?
There is a header and footer html file you could alter.
You place these in the templates folder.

In the javascript file you could:
Code: Select all
//__________________________________________________________________
//

var xmlHttp;

//__________________________________________________________________
//

function SentMail()
{
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null)
      {
         alert ("Browser does not support HTTP Request");
         return;
      }
   
      var url="includes/SentMail.php";
      url=url+"?sid="+Math.random();

      xmlHttp.onreadystatechange=function()
      {
         if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
         {
                          Alert("Mail sent");
         }
      
      }
      xmlHttp.open("GET",url,false);
      xmlHttp.send(null);
}


//__________________________________________________________________
//

function GetXmlHttpObject()
{
   var xmlHttp=null;
   try
    {
       // Firefox, Opera 8.0+, Safari
       xmlHttp=new XMLHttpRequest();
    }
   catch (e)
    {
       //Internet Explorer
       try
        {
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
    catch (e)
     {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
    }
   return xmlHttp;
}


In the file includes/SentMail.php you can use the mail() function from php and return the result true or false.
That is another way of doing this.

With regards,
Brian

PS English isn't my first language either. But I hope I have helped.