Confused about PHP script in form processing

darkroast

Member
I'm working on a form in which I want to run a PHP script when the form is submitted. I'm using the PHP Plugin, and it's set to process onAfterSubmit. Here's the code I have so far:

PHP:
<p>fedgov.php</p>
<?php
// No direct access
defined ('_JEXEC') or die ('Direct access to this location is prohibited');
 
        echo "<h3>Contact Your Federal Government</h3>";
        echo "<h4>Your email is being sent to the following people:</h4>";
echo "<pre>";print_r($formModel->_formData);exit;
?>

Couple questions come up when I run this:

1. I expect the display to show up within the template (in other words, in the content area), but instead it opens a new browser window with JUST the following on a white background:


fedgov.php
Contact Your Federal Government

Your email is being sent to the following people:



So, how do I get it to show up correctly?

2. I also used the code that should print out the structure of the elements (the last line of code). But it doesn't print.


What do I need to do?

Thanks!
 
Yeah, that's not going to work. The 'exit' literally stops the entire page load, not just your plugin.

The other issue is, we always do a redirect after a submission. So you can't just do a simple echo. You could enqueue a simple J! info message, will appear in the usual place at the top of the next page, by doing ...

Code:
$app = JFactory::getApplication;
$app->enqueueMessage("Your msg");

And I think we've renamed _formData to just formData in 3.1.

-- hugh
 
Ok, I got the array to display correctly (PS - you might want to update that in the wiki).

As for the "echo", here's what I'm trying to do; maybe you can suggest a way to do it if it's possible.

  1. When the user submits the form, the script should pull data from the table based on the selections he made on the form (this works fine).
  2. The script should send emails, one after another, using an email field in the table, to everyone who meets the criteria selected in #1 (this should work - haven't gotten that far yet, but I can code that).
  3. As the email is sent, the script should print to the screen the name of each person the email is sent to.
So, lets say there are three people in the table:
Adam​
Bobby​
Charlie​
The user selects criteria which would select Adam and Charlie, but not Bobby. What the script needs to do is send individual emails (because of different content) to both of them, one after the other using a loop. As it sends, what I'd like it to do is say:
Email successfully sent to Adam​
Email successfully sent to Bobby​
I hope that makes sense. Given what you said above, it might not be possible - at least, not easily. In which case, I can certainly use the
PHP:
$app = JFactory::getApplication;
$app->enqueueMessage("Your msg");

code you mentioned.

This may be a dumb question, but if I did it that way, would I put that code at the end of the script, so that after the messages have been sent, if successful, the message would show up on the redirected page? Would that be shown as a "success" message? If so, how would I show an "error" message - if, say, the email process failed?

Thanks for the help!
 
I'd just queue up one message per send attempt, saying either "Mail to XXX was sent" or "Mail to YYY failed". Each one will get shown, one per line, in J!'s usual Info message area, on the next page that user loads (usually the auto redirect).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top