trim function issues
Posted on
16th Feb 2014 07:03 pm by
admin
Hi guys, total noob here...
So I've been tinkering around with a html and am using php to email the subitted data to me. It's all working fine, except now I've changed the rules of the form a little and I can't seem to make it do a very simple task of converting field data to a string so that I can have it in the body of the email.
Here's the code:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['name']) == '') {
$hasError = true;
} else {
$name = trim($_POST['name']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'mickyginger@googlemail.com'; //Put your own email address here
$subject = 'Interest from the website';
$body = $name . $email;
$headers = 'From:' .$name. '<'.$email.'>' . "rn" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
Which works fine and dandy, only there are other fields like 'date' and 'venue' which I want to add to the body of the email regardless of whether they have been left blank or not.
Basically I want it to do something like this:
If the form is submitted
if name is not empty
$name = trim($_POST['name']);
if email is not empty
$email = trim($_POST['name']);
if number is empty OR if not
$number = trim($_POST['number']);
if date is empty OR if not
$date = trim($_POST['date']);
if there is no error
$body = $name . $email . $number . $date
seems like it should be really simple but I've tried everything I can think of with no joy...
No comments posted yet
Your Answer:
Login to answer
173
28
Other forums
quotes changing
hi all
in my content
opening quotes " changes to “
close qu
LIMIT $start, 10... how to pass last value queried into next page with GET??
Ok I know how to display the first or last 10 results of a query...
$result = mysql_query(&q
GIS appliction help
I found some tutorials in the internet to develop a map application I don't want to use google maps
Preg_match unknown modifyer
Hello,
Im trying to write a little script for my forums i need to get the reply from my forum
cURL and Sessions
Ohai.
So, I'm trying to cURL a bunch of things off of a page, and put them into a session. I'
Variable uses and placement
I'm new to PL/SQL and am trying to learn about variable valid uses/placement (any pointers to any do
Using two $_POST Function / Switch () statements, second does not work.
Hi all. I’m new to php and am having a problem getting $_POST Function / switch () to work. I
ALV List Display to point to another report on Double Click
Hi,
I want my ALV List Display to point to another report on Double Click on its line ite
Random Number Generation And Probability
Hello, I am working on a function which has to insert data into a SQL table.
we have to suppl
adding up might be solved tell us cheers.
i think i finally solved this anybody.
last time i was getting the wrong results.
Code