Hello,
I have a custom form (see here) with a lot of fields. Some are required, some are not.
How can I set chronoform to check if the fields are not empty before sending the form by email ? And if they are empty, to not send them of course...
Thx ! :ugeek:
I have a custom form (see here) with a lot of fields. Some are required, some are not.
How can I set chronoform to check if the fields are not empty before sending the form by email ? And if they are empty, to not send them of course...
Thx ! :ugeek:
Hi dangee,
You can do this using a template built in a Custom Code action. Use PHP to check the results and include/exclude which ever parts you need. I'd do it something like this:
Bob
You can do this using a template built in a Custom Code action. Use PHP to check the results and include/exclude which ever parts you need. I'd do it something like this:
<?php
$template = array();
$template[] = '<p>some introduction</p>';
if ( $form->data['some_input'] == 'some_value' ) {
$template[] = '<p>Label: {some_input}</p>';
}
. . .
$form->data['email_template'] = implode("/n", $template');
?>
Them put {email_template} in the Email template.
Bob
Thx GreyHead,
Where do I put the custom code ? on the Submit event ? before or after the email template ?
Where do I put the custom code ? on the Submit event ? before or after the email template ?
Hi dangee,
In the logical place - in the On Submit event after any validations or anti-spam checks and before the Email action.
Bob
In the logical place - in the On Submit event after any validations or anti-spam checks and before the Email action.
Bob
Hi, I'm still confused as I'm not getting the results I need (empty fields still appear) and place before my Email template.
My code I place as under Events tab -- Core Actions --> Custom code:
Using Chronoform v4. Joomal 2.5.20
thanks
My code I place as under Events tab -- Core Actions --> Custom code:
<?php
$input_array = array(
`Position` => `position1`,
`First` => `officerfirstname1`,
`Last` => `officerlastname1`,
`Phone` => `officerphone1`,
`Email ` => `officerEmail1`,
`President's Mailing Preference:` => `RECIEVE_LUP`,
`Position` => `officerposition2`,
`First` => `officerfirstname2`,
`Last` => `officerlastname2`,
`Phone` => `officerphone2`,
`Email` => `officeremail2`,
`Position` => `officerposition3`,
`First` => `officerfirstname3`,
`Last` => `officerlastname3`,
`Phone` => `officerphone3`,
`Email` => `officeremail3`,
`Position` => `officerposition5`,
`First` => `officerfirstname5`,
`Last` => `officerlastname5`,
`Phone` => `officerphone5`,
`Email` => `officeremail5`,
`Position ` => `officerposition6`,
`First` => `officerfirstname6`,
`Last` => `officerlastname6`,
`Phone` => `officerphone6`,
`Email` => `officeremail6`,
`Position` => `committeechair`,
`First` => `chairfirstname1`,
`Last` => `chairlastname1`,
`Phone` => `chairphone1`,
`Email` => `chairemail1`,
`Position` => `committeechair2`,
`First` => `chairfirstname2`,
`Last` => `chairlastname2`,
`Phone` => `chairphone2`,
`Email` => `chairemail2`,
`Position` =>` `chairposition3`,
`First` =>` => `chairfirstname3`,
`Last` =>` => `chairlastname3`,
`Phone` =>` => `chairphone3`,
`Email` =>` => `chairemail3`,
`Position` =>` `chairposition4`,
`First` =>` => `chairfirstname4`,
`Last` =>` => `chairlastname4`,
`Phone` =>` => `chairphone4`,
`Email` => `chairemail4`,
`Position ` => `chairposition5`,
`Firs` => `chairfirstname5`,
`Last` => `chairlastname5`,
`Phone` => `chairphone5`,
`Email` => `chairemail5`,
`Position` => `chairposition6`,
`First` => `chairfirstname6`,
`Last` => `chairlastname6`,
`Phone` => `chairphone6`,
`Email` => `chairemail6`,
`Position` => `chairposition7`,
`First` => `chairfirstname7`,
`Last` => `chairlastname7`,
`Phone` => `chairphone7`,
`Email` => `chairemail7`,
`Position` => `chairposition8`,
`First` => `chairfirstname8`,
`Last` => `chairlastname8`,
`Phone` => `chairphone8`,
`Email` => `chairemail8`,
$address = array();
foreach ( $input_array as $k => $v ) {
$temp = JRequest::getVar($k, '', 'post');
if ( $temp ) {
$address[] = "$v : $temp";
}
}
JRequest::setVar('address', implode('<br />', $address));
?>
Please let me know where I am going wrong;
Using Chronoform v4. Joomal 2.5.20
thanks
Here's my email template. I'm almost there, I can't get the labels to appear; just the completed fields. Please advise.
<?php
echo " ".JRequest::getString('schoolName', '', 'post')."<br />";
echo " ".JRequest::getString('email', '', 'post')."<br />";
echo " ".JRequest::getString('streetaddress', '', 'post')."<br />";
echo " ".JRequest::getString('city', '', 'post')."<br />";
echo " ".JRequest::getString('state', '', 'post')."<br />";
echo " ".JRequest::getString('zipcode', '', 'post')."<br />";
echo " ".JRequest::getString('location', '', 'post')."<br />";
echo " ".JRequest::getString('district', '', 'post')."<br />";
echo " ".JRequest::getString('EIN', '', 'post')."<br />";
echo " ".JRequest::getString('position1', '', 'post')."<br />";
echo " ".JRequest::getString('officerfirstname1', '', 'post')."<br />";
echo " ".JRequest::getString('officerlastname1', '', 'post')."<br />";
echo " ".JRequest::getString('officerphone1', '', 'post')."<br />";
echo " ".JRequest::getString('officerEmail1', '', 'post')."<br />";
echo " ".JRequest::getString('RECIEVE_LUP', '', 'post')."<br />";
echo " ".JRequest::getString('officerposition2', '', 'post')."<br />";
echo " ".JRequest::getString('officerfirstname2', '', 'post')."<br />";
echo " ".JRequest::getString('officerlastname2', '', 'post')."<br />";
echo " ".JRequest::getString('officerphone2', '', 'post')."<br />";
echo " ".JRequest::getString('officeremail2', '', 'post')."<br />";
echo " ".JRequest::getString('officerposition3', '', 'post')."<br />";
echo " ".JRequest::getString('officerfirstname3', '', 'post')."<br />";
echo " ".JRequest::getString('officerlastname3', '', 'post')."<br />";
echo " ".JRequest::getString('officerphone3', '', 'post')."<br />";
echo " ".JRequest::getString('officeremail3', '', 'post')."<br />";
echo " ".JRequest::getString('officerposition5', '', 'post')."<br />";
echo " ".JRequest::getString('officerfirstname5', '', 'post')."<br />";
echo " ".JRequest::getString('officerlastname5', '', 'post')."<br />";
echo " ".JRequest::getString('officerphone5', '', 'post')."<br />";
echo " ".JRequest::getString('officeremail5', '', 'post')."<br />";
echo " ".JRequest::getString('officerposition6', '', 'post')."<br />";
echo " ".JRequest::getString('officerfirstname6', '', 'post')."<br />";
echo " ".JRequest::getString('officerlastname6', '', 'post')."<br />";
echo " ".JRequest::getString('officerphone6', '', 'post')."<br />";
echo " ".JRequest::getString('officeremail6', '', 'post')."<br />";
echo " ".JRequest::getString('committeechair', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname1', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname1', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone1', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail1', '', 'post')."<br />";
echo " ".JRequest::getString('committeechair2', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname2', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname2', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone2', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail2', '', 'post')."<br />";
echo " ".JRequest::getString('chairposition3', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname3', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname3', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone3', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail3', '', 'post')."<br />";
echo " ".JRequest::getString('chairposition4', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname4', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname4', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone4', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail4', '', 'post')."<br />";
echo " ".JRequest::getString('chairposition5', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname5', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname5', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone5', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail5', '', 'post')."<br />";
echo " ".JRequest::getString('chairposition6', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname6', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname6', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone6', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail6', '', 'post')."<br />";
echo " ".JRequest::getString('chairposition7', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname7', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname7', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone7', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail7', '', 'post')."<br />";
echo " ".JRequest::getString('chairposition8', '', 'post')."<br />";
echo " ".JRequest::getString('chairfirstname8', '', 'post')."<br />";
echo " ".JRequest::getString('chairlastname8', '', 'post')."<br />";
echo " ".JRequest::getString('chairphone8', '', 'post')."<br />";
echo " ".JRequest::getString('chairemail8', '', 'post')."<br />";
?>
sorry the first few lines highlighted does not exist.
echo " ".JRequest::getString('schoolName', '', 'post')."<br />";
echo " ".JRequest::getString('email', '', 'post')."<br />";
echo " ".JRequest::getString('streetaddress', '', 'post')."<br />";
echo " ".JRequest::getString('city', '', 'post')."<br />";
echo " ".JRequest::getString('state', '', 'post')."<br />";
echo " ".JRequest::getString('zipcode', '', 'post')."<br />";
echo " ".JRequest::getString('location', '', 'post')."<br />";
echo " ".JRequest::getString('district', '', 'post')."<br />";
echo " ".JRequest::getString('EIN', '', 'post')."<br />";
HI amheng5,
Sorry, but I'm not sure what you are doing here.
The first code you posted is buggy - the first array doesn't close and the quotes look odd.
The second block of code will work but doesn't show any labels because you haven't added any and, if you do, it will show them regardless of whether there is a value submitted.
Bob
Sorry, but I'm not sure what you are doing here.
The first code you posted is buggy - the first array doesn't close and the quotes look odd.
The second block of code will work but doesn't show any labels because you haven't added any and, if you do, it will show them regardless of whether there is a value submitted.
Bob
Hi,
The first code block is copied from another thread but i changed the field name. I want to show only label and fields with content entered; I don't want to show labels with empty fields. I tried to understand the other forum threads on this topic but I'm not having any success. Hope you can make it clearer for me. Thankx
The first code block is copied from another thread but i changed the field name. I want to show only label and fields with content entered; I don't want to show labels with empty fields. I tried to understand the other forum threads on this topic but I'm not having any success. Hope you can make it clearer for me. Thankx
Hi Amheng,
You will need to use PHP code in the email template box and for this the editor must be kept disabled, here is an example:
You will repeat this code for every conditional field you have!
Regards,
Max
You will need to use PHP code in the email template box and for this the editor must be kept disabled, here is an example:
<?php if(!empty($form->data["field_name"])): ?>
Label: {field_name}
<?php endif; ?>
You will repeat this code for every conditional field you have!
Regards,
Max
This topic is locked and no more replies can be posted.