Reputation: 183
Yes, I am mentally challenged tonight. If anyone could help, that'd be very cool.
I just need to add a line break to the php string of a return message after the 'out'.
PHP FILE
// CHANGE THE TWO LINES BELOW
$email_to = "[email protected]";
$email_subject = "message submission";
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$message = $_POST['message']; // required
$email_message = "Form details below.nn";
$email_message .= "Name: ".$name."n";
$email_message .= "Email: ".$email_from."n";
$email_message .= "Message: ".$message."n";
$headers = 'From: '.$email_from."rn".
'Reply-To: '.$email_from."rn" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
// return all our data to an AJAX call
echo json_encode($data);
JS FILE
scotchApp.controller('FormController',function($scope, $http) {
// creating a blank object to hold our form information.
//$scope will allow this to pass between controller and view
$scope.formData = {};
// submission message doesn't show when page loads
$scope.submission = false;
// Updated code thanks to Yotam
var param = function(data) {
var returnString = '';
for (d in data){
if (data.hasOwnProperty(d))
returnString += d + '=' + data[d] + '&';
}
// Remove last ampersand and return
return returnString.slice( 0, returnString.length - 1 );
};
$scope.submitForm = function() {
$http({
method : 'POST',
url : 'process.php',
data : param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
if (!data.success) {
// if not successful, bind errors to error variables
$scope.errorName = data.errors.name;
$scope.errorEmail = data.errors.email;
$scope.errorTextarea = data.errors.message;
$scope.submissionMessage = data.messageError;
$scope.submission = true; //shows the error message
} else {
// if successful, bind success message to message
$scope.submissionMessage = data.messageSuccess;
$scope.formData = {}; // form fields are emptied with this line
$scope.submission = true; //shows the success message
}
});
I just can't seem to make it work. terribly entry level, I know.
If it helps: I am using php/angular/bootstrap. Anyway. thanks.
Upvotes: 2
Views: 2359
Reputation: 13665
One way would be using PHP_EOL constant and nl2br function:
<?php
$data['messageSuccess'] = 'Thanks for reaching out'.PHP_EOL.' We will contact you shortly. ';
echo nl2br($data['messageSuccess']);
?>
or using \n :
<?php
$data['messageSuccess'] = "Thanks for reaching out.\n We will contact you shortly.";
echo nl2br($data['messageSuccess']);
?>
If you don't have error reporting enabled, and it seems you don't, you can do it like this:
<?php
// Turn off error reporting
error_reporting(0);
// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>
Upvotes: 1
Reputation: 679
Use <br />
or \n
to "force" a new line. Or you can wrap your sentence into <p>
tags like this:
$data['messageSuccess'] = '<p>Thanks for reaching out.</p> <p>We will contact you shortly. </p>';
Upvotes: 0