bbw82 Posted December 2, 2011 Share Posted December 2, 2011 I have a form where people will be putting in specific info such as their names and other info. When the form is posted I need to add a "." between the fields on the output depending on if it is filled out or not if field is blank do not need a "." Example if they put in their name Bob Marley on the form I need it to appear on the output as Bob.Marley. Here is the code using currently which also excludes blank fields echo $_POST["First"]; if(isset($_POST["Middle"])){ echo $_POST["Middle"]; } echo $_POST["Last"]; Quote Link to comment Share on other sites More sharing options...
Spring Posted December 2, 2011 Share Posted December 2, 2011 Hi. I'd suggest changing your code to what Mj mentioned. http://www.phpfreaks.com/forums/index.php?topic=349006.0 use isset Um, let's not, since that won't work. A field that a users does not fill in a value for is still set - it just happens to have a value of an empty string. And, you should always use trim() on user input. Otherwise, a value of only spaces will appear as having a non-empty value. $first = trim($_POST['First']); $middle = trim($_POST['Middle']); $last = trim($_POST['Last']); $personal = trim($_POST['Persona1']); if(!empty($middle)) { $middle = $middle.'.'; } echo "{$first}.{$middle}{$last}.{$personal}.<br>\n"; Although you should really think about using htmlentities() on the values to prevent any values that might be interpreted as HTML code from screwing up the page. Quote Link to comment Share on other sites More sharing options...
marcus Posted December 2, 2011 Share Posted December 2, 2011 $first = "Bob"; $last = "Marley"; echo $first . "." , (isset($middle))? $middle."." : "" , $last . "."; Will just print "Bob.Marley." when $middle has no value. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.