Hy. I have made a form in html, bootstrap, php and I used Swift mailer setups for sending the e-mails.
In my form, I have a requirement that asks the respondent if he needs Visa, in the case that he answers “YES” another form appears. If he answers “NO”, then he is able to submit the form. My question it is: How can I construct the message body to appear in accordance with this condition? I mean, when the respondent chooses “NO”, the message to contain only the information asked for and if he choose YES, then the message to contain also the rest of the information?
In this moment the mail isn’t sending. (I used the same syntax php for sending mails from Contact US form and it works).
Thank you for you time.
[code]
Koblenz, Germany
<div class="col-sm-6">
<label for="venue" class="control-label">Dates:</label>
</br>
<label>
<p> 22nd - 28th April 2017 </p>
</label>
</div>
Full name:
Residential address (Street, City, Postal code, Country):
Other remarks or questions:
If you need visa, please complete the following data:
<label for="firstName" class="control-label">Full name(as written in the passaport):</label>
<div class="form-group">
<div class="col-sm-6 padding-top-10">
<input type="text" class="form-control" name="first_name" data-parsley-pattern="^[a-zA-Z ]+$" id="first_name" placeholder="First" />
</div>
<div class="col-sm-6 padding-top-10">
<input type="text" class="form-control" name="last_name" data-parsley-pattern="^[a-zA-Z ]+$" id="last_name" placeholder="Last" />
</div>
</div>
<div class="form-group">
<div class="col-sm-4 padding-top-10">
<label for="dateofBirth" class="control-label">Date of birth:</label>
<input type="text" class="form-control" name="dateof_birth" data-parsley-trigger="keyup" data-parsley-pattern="/^(\d{1,2})(\/|.)?(\d{1,2})(\/|.)?(\d{4})$/" placeholder="MM.DD.YYYY" data-date-format="MM.DD.YYYY" id="dateof_birth" />
</div>
<div class="col-sm-4 padding-top-10">
<label for="placeofBirth" class="control-label">Place of birth:</label>
<input type="text" class="form-control" name="placeof_birth" data-parsley-pattern="^[a-zA-Z ]+$" id="placeof_birth" placeholder="your place of birth" />
</div>
<div class="col-sm-4 padding-top-10">
<label for="nationality" class="control-label">Nationality:</label>
<input type="text" class="form-control" name="nationality" data-parsley-pattern="^[a-zA-Z ]+$" id="nationality" placeholder="your nationality" />
</div>
</div>
<div class="form-group">
<div class="col-sm-3 padding-top-10">
<label for="passaport" class="control-label">Passaport number:</label>
<input type="text" class="form-control" name="passaport" data-parsley-trigger="keyup" data-parsley-minlength="7" data-parsley-maxlength="10" id="passaport" placeholder="your passaport number" />
</div>
<div class="col-sm-3 padding-top-10">
<label for="dateofIssue" class="control-label">Date of issue:</label>
<input type="text" class="form-control" name="dateofIssue" data-parsley-trigger="keyup" data-parsley-pattern="/^(\d{1,2})(\/|.)?(\d{1,2})(\/|.)?(\d{4})$/" placeholder="MM.DD.YYYY" data-date-format="MM.DD.YYYY" id="dateofIssue" />
</div>
<div class="col-sm-3 padding-top-10">
<label for="placeofIssue" class="control-label">Place of issue:</label>
<input type="text" class="form-control" name="placeofIssue" data-parsley-pattern="^[a-zA-Z ]+$" id="placeofIssue" placeholder="place of issue" />
</div>
<div class="col-sm-3 padding-top-10">
<label for="dateofExpiry" class="control-label">Date of expiry:</label>
<input type="number" class="form-control" name="dateofExpiry" data-parsley-trigger="keyup" data-parsley-pattern="/^(\d{1,2})(\/|.)?(\d{1,2})(\/|.)?(\d{4})$/" placeholder="MM.DD.YYYY" data-date-format="MM.DD.YYYY" id="dateofExpiry" />
</div>
</div>
<label for="address" class="control-label padding-top-10">Residence address:</label>
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" data-parsley-minlength="10" data-parsley-trigger="keyup" name="residence_address" id="residence_address" placeholder="address" />
</div>
</div>
<div class="form-group">
<div class="col-sm-4 padding-top-10">
<label for="occupation" class="control-label">Occupation:</label>
<input type="text" class="form-control" name="occupation" data-parsley-pattern="^[a-zA-Z ]+$" id="occupation" placeholder="your occupation" />
</div>
<div class="col-sm-8 padding-top-10">
<label for="addressOfEmployer" class="control-label">Address of employer:</label>
<input type="text" class="form-control" name="addressOfEmployer" data-parsley-minlength="10" data-parsley-trigger="keyup" id="addressOfEmployer" placeholder="address of your employer" />
</div>
</div>
I have also a JS part:
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('ifYes').style.display = 'block';
} else {
document.getElementById('ifYes').style.display = 'none';
}
}
And the php page:
[php]<?php
require_once(‘vendor/autoload.php’);
define(‘EMAIL_TO’, ‘[email protected]’ );
$firstName = filter_input(INPUT_POST, ‘firstName’);
$lastName = filter_input(INPUT_POST, ‘lastName’);
$dateofBirth=filter_input(INPUT_POST, ‘dateofBirth’);
$gender=filter_input(INPUT_POST, ‘gender’);
$country=filter_input(INPUT_POST, ‘country’);
$email = filter_input(INPUT_POST, ‘email’);
$phone= filter_input(INPUT_POST, ‘phone’);
$address=filter_input(INPUT_POST, ‘address’);
$englishLevel=filter_input(INPUT_POST, ‘englishLevel’);
$profession=filter_input(INPUT_POST, ‘profession’);
$remarks=filter_input(INPUT_POST, ‘remarks’);
$first_name = filter_input(INPUT_POST, ‘first_name’);
$last_name = filter_input(INPUT_POST, ‘last_name’);
$dateof_birth=filter_input(INPUT_POST, ‘dateof_birth’);
$placeof_birth=filter_input(INPUT_POST, ‘placeof_birth’);
$nationality=filter_input(INPUT_POST, ‘nationality’);
$passaport=filter_input(INPUT_POST, ‘passaport’);
$dateofIssue=filter_input(INPUT_POST, ‘dateofIssue’);
$placeofIssue=filter_input(INPUT_POST, ‘placeofIssue’);
$dateofExpiry=filter_input(INPUT_POST, ‘dateofExpiry’);
$residence_address=filter_input(INPUT_POST, ‘residence_address’);
$occupation=filter_input(INPUT_POST, ‘occupation’);
$addressOfEmployer=filter_input(INPUT_POST, ‘addressOfEmployer’);
$data= "Name: " . $firstName . ’ ’ . $lastName . “\n” .
"Date of birth: " .$dateof_birth . “\n”.
"Gender: " .$gender . “\n”.
"Country: " . $country . “\n” .
"Email: " . $email. “\n” .
"Phone: " .$phone . “\n”.
"Address: " .$address . “\n” .
"Level of English: " .$englishLevel . “\n” .
"Occupation or profession: " .$profession . “\n” .
"Other remarks or questions: " .$remarks . “\n”.
"Name: " . $first_name . ' ' . $last_name . "\n" .
"Date of birth: " .$dateof_birth . "\n" .
"Place of birth: " .$placeof_birth . "\n" .
"Nationality: " .$nationality . "\n" .
"Passaport: " .$passaport . "\n" .
"Date of issue: " .$dateofIssue . "\n" .
"Place of issue: " .$placeofIssue . "\n" .
"Date of expiry:" .$dateofExpiry . "\n" .
"Residence address: " .$residence_address . "\n" .
"Profession: " .$occupation . "\n" .
"Address of employer: " .$addressOfEmployer . "\n" ;
if( $firstName && $lastName && $dateofBirth && $gender && $country && $email && $phone && $address && $englishLevel && $profession && $remarks ) {
// Create the Transport
$transport = Swift_SmtpTransport::newInstance(‘localhost’, 25)
->setUsername(‘user’)
->setPassword(‘password’)
;
$mailer = Swift_Mailer::newInstance($transport);
//http://swiftmailer.org/docs/sending.html
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('From CRCE ROMANIA - The Power of Nonformal form')
// Set the From address with an associative array
->setFrom(array('[email protected]' => 'CRCE ROMANIA'))
// Set the To addresses with an associative array
->setTo(array(EMAIL_TO))
// Give it a body
->setBody($data, 'text/plain');
$result = $mailer->send($message);
header("Location: index.php?pagina=success");
} else {
var_dump(“xxx”);
}
[/php]