#1 2015-10-02 16:11:16

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

[SOLVED] Email from in simpleForm-module [0.9.7]

I have an old site still running on ionize 0.9.7
It uses a webform that works fine, but they want to change the following:
In the file simpleform-action (modules/Simpleform/libraries/simpleform-action.php) the From is standard set to the website email setting ($ci->email->to($config['simpleform_' . $form_name . '_email']);).
They would like that to be the form email (email filled out in the form).
Is there a simple solution for it ... ?
Thanks in advance
Greet

Last edited by greet (2015-10-25 00:19:01)

Offline

#2 2015-10-14 22:09:23

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

Hello,
Can you share the full php source?


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#3 2015-10-15 12:25:14

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

Hi Adamos,

Thx for looking at it. The code is :

public function process_data($tag)
	{
		
		$ci =  &get_instance();

		if ( ! isset($ci->simpleform_validation))
			$ci->load->library('simpleform_validation');

		/**
		 * Check the rules defined in config.php for the given form name
		 * and proccess the form data.
		 *
		 * Here, it sends a mail with the form data.
		 *
		 */
		if ($ci->input->post('form_name') !== FALSE && config_item('simpleform_' . $ci->input->post('form_name')))
		{
			$form_name = $ci->input->post('form_name');
			
			if ($this->check_form($form_name))
			{
				try
				{
					// Config
					include MODPATH . 'Simpleform/config/config.php';

					// Email Lib
					if (!isset($ci->email))	$ci->load->library('email');
					
					// Email Title
					$title = isset($config['simpleform_' . $form_name . '_email_title']) ? lang($config['simpleform_' . $form_name . '_email_title']) : Settings::get("site_title");
					$ci->email->subject($title);
					
					// From : Standard website's email
					$ci->email->from(Settings::get("site_email"), Settings::get("site_title"));
					
					// To : As defined in config.php
					if (isset($config['simpleform_' . $form_name . '_email']))
					{
						$ci->email->to($config['simpleform_' . $form_name . '_email']);
					}
					else
					{
						throw new Exception(
							'SimpleForm module error : No destination Email set in "<b>'.MODPATH.'Simpleform/config/config.php</b>" for the form called : <b>'.$form_name.'</b><br/>'.
							'Please setup the config item : $config[\'simpleform_'.$form_name.'_email\']'
						);
						
					}
					
					// Email view
					if (file_exists(MODPATH.'Simpleform/views/'.$config['simpleform_' . $form_name . '_email_view'].EXT))
					{
						$ci->email->message($tag->parse_as_nested(file_get_contents(MODPATH.'Simpleform/views/'.$config['simpleform_' . $form_name . '_email_view'].EXT)));

						$ci->email->send();

						$ci->simpleform_validation->additional_success['profile'] = lang("module_usermanager_text_registered") . " <a href=''>".lang("module_usermanager_text_registered_here")."</a>.";
					}
					else
					{
						throw new Exception(
							'SimpleForm module error : No Email View set in "<b>'.MODPATH.'Simpleform/config/config.php</b>" for the form called : <b>'.$form_name.'</b><br/>'.
							'Please setup the config item : $config[\'simpleform_'.$form_name.'_mail_view\']'
						);
					}
				}
				catch(Exception $e)
				{
					$ci->simpleform_validation->additional_err['register'] = $e->getMessage();
				}
			}
		}

		$ci->simpleform_validation->check_additional_errors();
	}

The email used for from should be the email from the senders email (email provided in the webform) and not as set in ionize admin

// From : Standard website's email
$ci->email->from(Settings::get("site_email"), Settings::get("site_title"));

Offline

#4 2015-10-17 16:19:59

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

greet wrote:

The email used for from should be the email from the senders email (email provided in the webform) and not as set in ionize admin

// From : Standard website's email
$ci->email->from(Settings::get("site_email"), Settings::get("site_title"));

Then try use the post email field:

$ci->email->from( $ci->input->post('email_field_name'), $ci->input->post('sender_name'));

Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#5 2015-10-17 19:25:36

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

Hi Adamos,

Thanks, this worked :-)

I did encounter another problem in the form handling.
The actual form can be found here: http://www.sportmolenstede.be/inschrijvingen
It contains a multi-select field. But it only sends the first selected item in the email sent to the client.

This site was built using ionize 0.9.7 and uses, as said above, the simple form module.

Greet

Offline

#6 2015-10-17 19:39:35

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

Change the select name:

<select name="les[]" multiple="multiple" size="10">

And after that in php you should have a $ci->input->post('les') with a selected array.


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#7 2015-10-17 19:59:46

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

one more thing ... where do I loop through the array to get the different values to pass to the view ?
some function in simpleform_action.php ?

Offline

#8 2015-10-17 22:43:32

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

you can do it in the view I think, if you have tagmanager there then it should work with expand like articles if you dont have then a simple foreach should do the work.


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#9 2015-10-18 00:01:24

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

In the view I have <ion:field name="les" from_post_data="inschrijving" />
This gives me 'array' in the email that is sent.
How do I have to use 'expand' like in articles ? I can't find any info in the user docs.

Offline

#10 2015-10-18 01:08:47

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

The expand means the begin-end version of the tag like: <ion:articles> [...] </ion:articles>, the FTL Library processing the blocks and if a block has a expand method there you can use it like a foreach. Unfortunatley we dont have a technical documentation for explain how its work. sad

The ion:field executing the tag_expand method in tagmanager (see in the ./application/libraries/tagmanager/Form.php::$tag_definitions) so the:

<ion:field name="les" from_post_data="inschrijving">
    <ion:trace />
</ion:field>

should work, also in the Form class I see we have a ion:select also, so thats more logical for use:

<ion:select name="les" from_post_data="inschrijving">
    <ion:trace />
</ion:select>

if not then you can do it by using the tag as a php value (littebit hacked):

<?php $les = (array) '<ion:field name="les" from_post_data="inschrijving" />'; ?>
[...]
<p> Values: <ul>
<?php foreach($les as $i => $value): ?>
    <li> <?php echo $value; ?> </li>
<?php endforeach; ?>
</ul> </p>
[...]

Hope this work, I did not tested smile


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#11 2015-10-18 15:28:13

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

unfortunately it doesn't work ...
I think we are coming close but my understanding of php is really poor.
So I put the following code-block in my view (view for email)

<strong>Inschrijving voor</strong> : 
<ion:field name="les" from_post_data="inschrijving" />
   		<?php $les = array('<ion:field name="les" from_post_data="inschrijving" />'); ?>
               <ul>
			<?php foreach($les as $i => $value): ?>
			<li> <?php echo $value; ?> </li>
			<?php endforeach; ?>
	      </ul>

In my error log I don't get anny error. In the email i get
email captyre

Last edited by greet (2015-10-18 15:30:19)

Offline

#12 2015-10-18 17:17:50

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

hmm change the field value before the view load:

$_POST['les'] = implode(', ',$ci->input->post('les'));

or you can save the array int the session and use the foreach:

// In the process php before the view load
$_SESSION['les'] = $ci->input->post('lese')

// In the view file
<ul>
    <?php foreach($_SESSION['les'] as $i => $value): ?>
    <li> <?php echo $value; ?> </li>
    <?php endforeach; ?>
</ul>

Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#13 2015-10-25 00:17:08

greet
Ion Tester
From: Belgium
Registered: 2012-05-07
Posts: 143

Re: [SOLVED] Email from in simpleForm-module [0.9.7]

Hi Adamos,

Everything solved now! Thanks for your patience and folow up.
For who's interested in the solution,
1/ in the form view define the field as an array with name="les[]"

<select name="les[]" multiple="multiple" size="10" />
      <ion:articles from="inschrijvingsmenu">
                <ion:elements type="inschrijvingsform-options">
                              <option value='<ion:field name="optie" />'><ion:field name="optie" /></option>
                </ion:elements>
     </ion:articles>
</select>

2/ make a string of your array in the file /modules/Simpleform/libraries/simpleform_actio.php , just before the view is loaded

$_POST['les'] = implode(', ',$ci->input->post('les'));

3/ then you can simply use in the Simpleform mail that is sent

<ion:field name="les" from_post_data="inschrijving" />

Last edited by greet (2015-10-25 00:17:47)

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations