Joomla Chronoforms Dynamic To - joomla

I have successfully created a basic Chronoforms form with the standard 'To' field sending the form data in an email to one recipient. However, I would like the 'To' field to become a 'Dynamic To' that will send the form to different users based off of the value of one of the dropdown fields I have in the form. I couldn't find any good documentation on how to use the 'Dynamic To' or accomplish this.
Anyone have any thoughts?

In chronoform you use the dynamic fields simply by writing the name of the form field into the respective E-Mail field.
So if the name of your dropdown is email_choice you write email_choice into the "Dynamic To" field of the E-Mail setup box and you're good to go.

How to show a drop down list of email recipients without displaying the email addresses publicly:
1. ChronoForms v3
Your drop down list in your HTML code will look something like this:
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Person to Contact:</label>
<select class="cf_inputbox" id="select_0" size="1" title="" name="Attn">
<option value="">Choose Option</option>
<option value="President">President</option>
<option value="Secretary">Secretary</option>
<option value="Treasurer">Treasurer</option>
etc
Enter this code in the 'On Submit code - before sending email' field:
<?php
$email_list = array(
'President'=>'president#organisation.com',
'Secretary'=>'secretary#organisation.com',
'Treasurer'=>'treasurer#organisation.com'
);
$MyForm =& CFChronoForm::getInstance('Contact');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $email_list[$_POST['Attn']]);
?>
This assumes your form name is "Contact".
In "Setup Emails", enter "Attn" in the "To" field.
2. ChronoForms v4
Your drop down list in your HTML code will look something like this:
<div class="ccms_form_element cfdiv_select" id="who_to_contact__container_div">
<label for="Who">Who to Contact:</label>
<select size="1" label_over="0" hide_label="0" id="Who" class=" validate['required']" title="Who" type="select" name="Who">
<option value="President">President</option>
<option value="Secretary">Secretary</option>
<option value="Treasurer">Treasurer</option>
etc
Enter some Custom Code In the Submit section with "Mode" set to "Controller":
<?php
$who = JRequest::getString('Who', 'Webmaster', 'post');
$emails = array(
'President' => 'president#organisation.com',
'Secretary' => 'secretary#organisation.com',
'Treasurer' => 'treasurer#organisation.com'
);
$form->data['Attn'] = $emails[$who];
?>
In Email -> Dynamic, set "Dynamic To" to: Attn
References:
http://chronoengine.com/forums/viewtopic.php?f=2&t=15263&p=45265
http://chronoengine.com/forums/viewtopic.php?f=5&t=16272&p=42909
http://chronoengine.com/forums/viewtopic.php?f=2&t=16839&p=45601

Related

Problem with form option selected where parameters in the url

Hi I have problem with my multiple select search form.
The parameters are in the url
urlhomepage.../search?cars=1&cars=2&cars=4
I do not know how to get parameters url in form option as selected
<select multiple="multiple" name="cars[]" id="select2" placeholder="">
#foreach($names as $name)
<option value="{{$name->id}}">{{$name->title}}</option>
#endforeach
</select>
I want to get the effect so that the form options are marked on the basis of a url query
First you should pass variable as array as cars[] like below
urlhomepage.../search?cars[]=1&cars[]=2&cars[]=4
Inside php you can get cars array form query string
<?php
$cars = request('cars',[]);
?>
And put cars value as auto selected in select
<select value="{{$cars}}" multiple="multiple" name="cars[]" id="select2" placeholder="">

Laravel Rules Validation - Only another field has a value

<input type="checkbox" name="grievance_discipline" value="checked">
<select name="grievance_type">
<option value="_none" selected>- Select One</option>
<option value="suspension">Suspension</option>
</select>
<?php
$this->validate($request,[
'grievance_type' => 'required_if:grievance_discipline, checked|not_in:_none',
]);
?>
The trouble I am running in to, is telling Laravel to ONLY use a particular validation rule if another field has a value.
In the example, the discipline_type field (a select list), is required IF grievance_discipline is checked.
The default select option for the select list is - Select One - with the value of _none. In the validation rules, _none should be thrown out, but it should ONLY validate on it if the grievance_discipline checkbox has value 'checked'.
Could anybody help me with this, please?
How about setting the first option as disabled so the user are forced to pick a value or not submitting a value, hence gracefully fail your validation check. Also, use required_with instead of required_if to check if another value exist or not.
<input type="checkbox" name="grievance_discipline" value="checked">
<select name="grievance_type">
<option disabled selected value>- Select One</option>
<option value="suspension">Suspension</option>
</select>
Then in the PHP, do
$this->validate($request,[
'grievance_type' => 'required_with:grievance_discipline'
]);

Rspec + Capybara: Validating select options using xpath

I have an HTML document (there is a DIV with an ID of "countries" that wraps this code below), and in that I need to -
Validate the options in the select. I tried this but this is not valid.
expect(page).to have_xpath(('//*[#id="countries"]//select')[1],
:options => ['US CAN GER POL'])
Validate that the second select is disabled
Validate that CAN is disabled in the first select
Validate that POL is selected in the first select
Change the selected option to GER in the first select
<li>
<fieldset>
<select>
<option value="US">USA</option>
<option value="CAN" disabled>Canada</option>
<option value="GER">Germany</option>
<option value="POL" selected>Poland</option>
</select>
<fieldset>
<li>
<li>
<fieldset>
<select disabled>
<option value="US">USA</option>
<option value="CAN">Canada</option>
<option value="GER">Germany</option>
<option value="POL">Poland</option>
</select>
<fieldset>
<li>
I appreciate any help that you can provide. Thanks!
Word of warning, I personally still use the should syntax for rspec, and I also use css selectors versus xpath. I simply find them easier to read.
(1) Because you have two dropdowns without any specific IDs or class names identifying one from the other, I would use all to restrict the context of your expectations
all('#countries select')[0].should have_text('USA Canada Germany Poland')
(2) Same concept as above, restrict the scope. Second fieldset should contain a disabled dropdown.
all('#countries fieldset')[1].should have_css('select[disabled]')
(3) all('#countries select')[0].should have_css('option[disabled]', :text => 'Canada')
(4) Same answer as #3 but with different attribute and text
(5) all('#countries select')[0].find('option', :text => 'Germany').click

Laravel 5 dropdown box do not pass back old value upon validation fail

I have a quick question. I made a dropdown box for gender selection in my registration form that looks like this:
<div class="col-md-6 col-sm-6">
<select name="gender" value="{{ old('gender') }}" class="form-control">
<option value=null>------ Gender ------</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
{!! MessagerService::setInlineError($errors->first('gender')) !!}
</div>
So what I do is upon a validation fail, the selected gender is not passed back to the form. Any ideas what I have done wrong? Thank you.
You don't have to write plain HTML. You can take advantage of Laravel Form Builder. In Laravel 5 it is not bundled by default, like it was in 4.2, so first you need to require it. Go to your project root and in terminal write:
composer require "illuminate/html":"5.0.*"
Then go to config/app.php and under providers add
'Illuminate\Html\HtmlServiceProvider',
You can register also those two facades under aliases:
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade',
After that you are ready to use Form facade to create your select with one simple line of code which will handle old input values:
{!! Form::select('gender', ['' => '--Gender--', 'male' => 'Male', 'female' => 'Female']) !!}
It is as simple as that. You can check the documentation to find out more useful methods of the Form facade.

Sending form field values to params hash - rails

I have a partial that I call in layouts/application.html.erb to display a form for a search. The user chooses values from the two select fields; then, should hit enter to render a view with search results.
Here is the partial:
** _search.html.erb:
<form name="classic">
<select name="countries" size="1" onChange="updatecities(this.selectedIndex)" style="width: 150px">
<option selected>Select A Brand</option>
<option value="usa">Opel</option>
<option value="canada">Cheverolet</option>
<option value="uk">Scoda</option>
</select>
<select name="cities" size="1" style="width: 150px">
</select>
</form>
<script type="text/javascript">
var countrieslist=document.classic.countries
var citieslist=document.classic.cities
var cities=new Array()
cities[0]=""
cities[1]=["Vectra|vectravalue", "Corsa|corsavalue"]
cities[2]=["Optra|optravalue", "Lanos|lanosvalue"]
cities[3]=["Octavia|octaviavalue", "Fleshia|fleshiavalue"]
function updatecities(selectedcitygroup){
citieslist.options.length=0
if (selectedcitygroup>0){
for (i=0; i<cities[selectedcitygroup].length; i++)
citieslist.options[citieslist.options.length]=new Option(cities[selectedcitygroup][i].split("|")[0], cities[selectedcitygroup][i].split("|")[1])
}
}
</script>
The javascript is just to filter the second select dropdown based on the first select dropdown. What I need to do is to send the values chosen in this form in the URL for params hash so that I can act on it in the controller and display the search results. I could use link_to.
How do I include the selected values from the form fields in link_to?
Your help is appreciated. Thanks!
Serialize the form and send the data to the server. The selected value is passed as the hashvalue where the key is the "id" for the select tag.

Resources