Forums

Email using relational data

dasofsky 03 Oct, 2010
I am hoping someone can help me out. I have a project with three input forms:

1) The standard Joomla registration form

2) Animal Input Form: Pet Name, Pet Type, Pet Vet, Vet Fax (One time input)

3) Create Fax Message: Pet Name (pulls from pet name field of animal input form) Is currently working, Type of visit, reason for visit (Can be used many times per animal)


Upon submitting the Create Fax Message form I would like to:

1) Send an email using fields from the Create Fax Message form (No problem to do)

2) Send to the fax number inputted in the Animal Input form for the pet name selected

3) append @rcfax.com to the to: field ... ex [email]9998887777@rcfax.com[/email]



I would appreciate any guidance/assistance anyone can offer!

Thanks in advance for your help,

DA
GreyHead 03 Oct, 2010
Hi DA,

You need to create some kind of Animal ID that will tie these together (I see you are suing the name, I'd be inclined to use a unique random string) .

I assume that one user might have more than one pet so I'd require a login for the Fax message form; then use the user_id to look up the pets that have registered and show a drop-down box (or radio buttons) for them to pick one. This would give you the Animal ID.

Then you can use that in the OnSubmit Before Box of the Fax email to look up the Animal data and add that into data fields that can be used in the email. Here's an example concatanating a To Email string in the OnSubmit Before box using
<?php
$animal_id = JRequest::getVar('animal_id', '', 'post');
if ( $animal_id ) {
  $db =& JFactory::getDBO();
  $query = "
      SELECT *
          FROM `#__animals`
          WHERE `animal_id` = '$animal_id' ;
  ";
  $db->setQuery($query);
  $data = $db->loadObject();

  $to_email = $data->VetFax."@@rcfax.com";
  JRequest::setVar('to_email', $to_email);
}
?>

Then you'd need to use a Dynamic To in the Email Setup with to_email in the box.

Bob
dasofsky 03 Oct, 2010
Bob,

Thank you very much for the quick reply. I am hoping to be more clear so I can get the proper response. This is the form code that works properly. I am using a different example with students. Since each parent will only have one to four kids I am using the student name and not a unique id:

WORKING FORM CODE FOR POPULATING A DROPDOWN MENU LISTING KIDS FOR A GIVEN PARENT:
<DIV class="form_item"   >
<DIV class="form_element cf_dropdown" >
 <label class="cf_label" style="width: 150px;">Student</label>
    <?php
   $user =& JFactory::getUser();

   $db =& JFactory::getDBO();
    $query = "SELECT st_first_name
        FROM jos_chronoforms_simple where cf_user_id={$user->id}";
    $db->setQuery($query);
    $rows = $db->loadResultArray();
    ?>
   
    <SELECT class="cf_inputbox validate-selection" id=select_4 size=1 name=nt_student>
<?php
    foreach ($rows as $row => $current) {
      echo "<option value='$current'>$current</option>";
    }
    ?>
    </select>
  </div>
  <div class="cfclear"> </div>
</div>


Relevant fields:

table with student info: jos_chronoforms_simple
Student Name Field: st_first_name
School Fax Field: st_school_fax

table with note info: jos_chronoforms_note_bus
Student Name Field: nt_student



Once again I am trying to:

1) Use the fax number (st_school_fax) inputted in the jos_chronoforms_simple table for the student name (nt_student) selected in the dropdown on form . The matching field in the jos_chronoforms_simple table is st_first_name

2) append @rcfax.com to the to: field ... ex [email]9998887777@rcfax.com[/email]


I would really appreciate any additional help you may offer.
dasofsky 03 Oct, 2010
This is the error message I am getting:

Parse error: syntax error, unexpected T_VARIABLE in /home/dasofsky/public_html/skytwins/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 4


This is the On Submit Before Code:
<?php
$nt_student = JRequest::getVar('nt_student', '', 'post');
if ( $nt_student ) {
  $db =& JFactory::getDBO();
  $query = "
      SELECT *
          FROM `jos_chronoforms_simple`
          WHERE `st_first_name` = '$nt_student'
  ";
  $db->setQuery($query);
  $data = $db->loadObject();

  $to_email = $data->st_school_fax."@@rcfax.com";
  JRequest::setVar('to_email', $to_email);
}
?>
GreyHead 04 Oct, 2010
Hi dasofsky,

Odd, it's flagging some kind of syntax error on line 4 of that code but I don't see any errors there? There must be something though.

Bob
dasofsky 04 Oct, 2010
Bob,

I have now got the code working. Upon the after email I am able to retrieve the correct fax value.

My problem now is this. I can not get the email to work. Even using static text I have not been able to get this to work.

The Joomla registration forms are sent with no problems. It seems to be something specific to ChronoForms. I have checked my spam systems and it is not getting trapped.

Any thoughts?

DA
GreyHead 04 Oct, 2010
Hi dasofsky,

This line should only have one @ - could that be the problem?

  $to_email = $data->st_school_fax."@@rcfax.com";


Bob
dasofsky 04 Oct, 2010
Bob,

I have attached info on a form that has no dynamic data and no after code. I still can't get it to send?
GreyHead 04 Oct, 2010
Hi daofsky,

There's some important info missing there - like the Email Setup.

Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
dasofsky 04 Oct, 2010
Bob,

Here is the result of the debug:

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [text_1] => Hey Hey [button_2] => Submit [430d6a8652d4804cc2e26ef8497c8a26] => 1 [1cf1] => c02f3a9d1717b06157d53225661131b3 [chronoformname] => email_test )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. Debug End

Thanks,

DA
dasofsky 05 Oct, 2010
Bob,

Thanks you very much for your help ... Apparently I didn't read the tutorial on sending emails. Everything is working now

DA
GreyHead 05 Oct, 2010
Hi dasofsky,

Great - good to hear that it's all working. I was just about to look at your form.

Bob
dasofsky 06 Oct, 2010
Bob,

I read all of the posts related to this and I am not sure I was clear about the answer.

Is there a way to email the form results as an html attachment?

DA
GreyHead 06 Oct, 2010
Hi dasofsky,

I think so, not something that I've done but I recall Fredrik (nml375) posting something about this. You'd open a file and write to it in the OnSubmit Before box then attach it to the email.

Bob
dasofsky 14 Oct, 2010
What is the correct syntax to add the number 1 to the beginning of the variable:

$to_email = $data->st_school_fax.'@rcfax.com';

lets say that st_school_fax was 7818466570

The current code will output: [email]7818466570@rcfax.com[/email]

I would like it to output [email]17188466570@rcfax.com[/email]

I hope this isn't a "newbie" question

Thanks in advance for your help

DA
GreyHead 14 Oct, 2010
Hi dasofsky,

$to_email = '1'.$data->st_school_fax.'@rcfax.com';


Bob
dasofsky 15 Oct, 2010
Can someone please let me know how to embed the {edit_record} function so I can link the first name field to initiate the edit process instead of having a link that says "edit" next to each row?

Thanks in advance for your help

DA
GreyHead 16 Oct, 2010
Hi dasofsky,

You can use a normal link that goes to the same URL as the Edit Record link.
<a href='index.php?option=com_chronoconnectivity&connectionname=articles&task=editrecord&cids={cf_id}'>{name}</a>


Bob
This topic is locked and no more replies can be posted.