How do I dynamically changed a form result layout using php

I have a form using php. Depending on one of the fields entered, I want to add extra info on the form result. I am having trouble with the syntax. I only want the code below printed out in the form result when a the address field has "ny" or "nyc" or "manhattan" entered in it

      <tr><td> This is to certify that I am an authorized officer of</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtCompanyName'] .  "</td></tr>
                        
                                    
                        <tr><td> Date:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtSignatureDate'] . "</td></tr>
                        <tr><td> Name:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtCompanyOfficer'] . "</td></tr>
                        <tr><td> Title:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtCompanyOfficerTitle'] . "</td></tr><br />
                <tr><td> Signature:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtSignature'] . "</td></tr>
                         <tr><td> Lien Amount $:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtExactOwed'] . "</td></tr>
                         
                         <tr><td colspan=\"3\">Block:</td></tr>
                         <tr><td colspan=\"3\">Lot:</td></tr>
                        
HidesignAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You have not shown us enough of the code to understand where to find ny or nyc, etc.  However the usual design pattern is to use an if() statement.
0
Ray PaseurCommented:
Also, you might want to consider simplifying your programming life by learning about HEREDOC notation - it will make the syntax much easier to read.
http://www.php.net/manual/en/language.types.string.php

Example...

$str = <<<END_OF_STRING
<td>$var</td>
END_OF_STRING;

No concatenation, no quotes, just variable substitution on $var -- really easy to get right!

HTH, ~Ray
0
Greg AlexanderLead DeveloperCommented:
Try
if (preg_match("/(ny|nyc|manhattan)/i", $_POST['addressfieldname'])){
	echo "HTML goes here";
}

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

HidesignAuthor Commented:
Thanks for yuour quiclk responeses. This is the filed I need to check for ny, nyc and manhattan. I
if ($_POST['ctl00$ContentPlaceHolder1$txtCompanyCity'] == "" )

If this field has any of those values, then I want to diplay the  lines put above in the form result. If these any of those values are not entered, then the form result should not display those fields and text

Thanks
0
Greg AlexanderLead DeveloperCommented:
Try
<?
if (preg_match("/(ny|nyc|manhattan)/i",$_POST['ctl00$ContentPlaceHolder1$txtCompanyCity'])){
echo "<tr><td> This is to certify that I am an authorized officer of</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtCompanyName'] .  "</td></tr>
                        
                                    
                        <tr><td> Date:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtSignatureDate'] . "</td></tr>
                        <tr><td> Name:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtCompanyOfficer'] . "</td></tr>
                        <tr><td> Title:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtCompanyOfficerTitle'] . "</td></tr><br />
                <tr><td> Signature:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtSignature'] . "</td></tr>
                         <tr><td> Lien Amount $:</td><td width=\"" . $width . "\"></td><td>" . $_POST['ctl00$ContentPlaceHolder1$txtExactOwed'] . "</td></tr>
                         
                         <tr><td colspan=\"3\">Block:</td></tr>
                         <tr><td colspan=\"3\">Lot:</td></tr>";
}	
?>

Open in new window

0
HidesignAuthor Commented:
Thanks - I put this code in and got a parsing error on the line below

Parse error: syntax error, unexpected '"' in /home3/speedyli/public_html/test-lien/formatEmail-field.php on line 330

if (preg_match("/(ny|nyc|manhattan)/i",$_POST['ctl00$ContentPlaceHolder1$txtCompanyCity'])){
0
Ray PaseurCommented:
If the error is on line 330, we may be missing a larger part of the picture.  You have not posted more than a handful of lines of code, so we are guessing about where the error really might be.  The if() with preg match above looks OK to me.
0
HidesignAuthor Commented:
Should attach the whole php page. Thanks so much for your help
0
HidesignAuthor Commented:
0
Greg AlexanderLead DeveloperCommented:
Try the attached
formatEmail-test.php
0
Greg AlexanderLead DeveloperCommented:
Actually This one, sorry
formatEmail-test.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HidesignAuthor Commented:
Thanks - I will try it
0
Ray PaseurCommented:
Have been away for a few hours, but I just got a look at that code.  It looks very complex for what it appears to be doing -- providing sanity checks and error messages for an HTML form.  I don't have time to rewrite it now, but I can help with a design pattern that might simplify things now, so when the time comes to modify the form you will have a more malleable script.  See if this makes sense.  It goes a little beyond the question of how to use preg_match in an if() statement, but hopefully it will stimulate your thinking about how the overall script structure can be simplified.

best regards, and good luck with the project, ~Ray
<?php // RAY_form_highlight_errors.php
error_reporting(E_ALL);


// DEMONSTRATE HOW TO HIGHLIGHT ERRORS IN FORM INPUT
// CLIENT IS ASKED TO PUT IN A VALUE
// IF THE VALUE FAILS OUR TEST WE SHOW AN ERROR MESSAGE
// WE PUT A MARKER NEXT TO THE INPUT CONTROL ON THE FORM
// SEE http://www.w3schools.com/CSS/pr_class_visibility.asp


// THESE CONDITIONS ARE SET FOR THE INITIAL ENTRY
$error_any = 'hidden';
$error_abc = 'hidden';
$error_xyz = 'hidden';

// CAPTURE AND NORMALIZE THE POST VARIABLES, IF ANY
$abc = (isset($_POST["abc"])) ? trim(strtoupper($_POST["abc"])) : NULL;
$xyz = (isset($_POST["xyz"])) ? trim(strtoupper($_POST["xyz"])) : NULL;

// IF ANYTHING WAS POSTED, VALIDATE IT
if (!empty($_POST))
{
    // VALIDATE THE 'abc' FIELD
    if ($abc != 'ABC')
    {
        $error_any = 'visible';
        $error_abc = 'visible';
        $abc       = NULL;
    }

    // VALIDATE THE 'xyz' FIELD
    if ($xyz != 'XYZ')
    {
        $error_any = 'visible';
        $error_xyz = 'visible';
        $xyz       = NULL;
    }

    // DO WE HAVE INPUT FREE FROM ANY ERRORS?
    if ($error_any != 'visible')
    {
        echo "CONGRATULATIONS";
        die();
    }
}

// IF NOTHING WAS POSTED, OR IF THERE ARE ERRORS, WE NEED NEW CLIENT INPUT
$form = <<<ENDFORM
<style type="text/css" media="all">
.error_any { visibility:$error_any; }
.error_abc { visibility:$error_abc; }
.error_xyz { visibility:$error_xyz; }
</style>
<pre>
<form method="post">
<span class="error_any">PLEASE CORRECT THE FOLLOWING ERRORS</span>
<span class="error_abc">YOU MUST ENTER 'abc' IN THIS FIELD</span>
PLEASE ENTER "ABC" HERE: <input name="abc" value="$abc" />
<span class="error_xyz">YOU MUST ENTER 'xyz' IN THIS FIELD</span>
PLEASE ENTER "XYZ" HERE: <input name="xyz" value="$xyz" />
<input type="submit" />
</form>
ENDFORM;

// WRITE THE FORM WITH THE APPROPRIATE CSS STYLES ON THE ERROR MESSAGE FIELDS
echo $form;

Open in new window

0
HidesignAuthor Commented:
Worked Perfectly
0
HidesignAuthor Commented:
Ray_Paseur: - thanks for your answer too. I will also try this logic and I appreciate your time spent on this
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.