2

I am trying to show text content just with a PHP if condition but I have several errors and I don’t see where is the error could someone help me with this, here is the code:

<?php
  if(
     isset($_POST['send']) &&
     !validateDiscp($_POST['Discp']) || !validateSize($_POST['Size'])
  ) : ?>

<div id="error">
  <ul>
    <?php if(!validateDiscp($_POST['Discp'])):?>
     <li><strong>Discription:</strong>Discription need to be larger then 10!</li>
    <?php endif?>
    <?php if(!validateSize($_POST['Size'])):?>
     <li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
    <?php endif ?>
      </ul>
</div>

<?php elseif(isset($_POST['send'])):?>
<div id="error" class="valid">
  <ul>
    <li><strong>Congratulations!</strong> All fields are OK ;)</li>
  </ul>
</div>
<?php endif ;?>
3
  • 1
    A couple of <?php endif ?> miss an ending semicolon - on the other hand there is a ;) smile :PP Commented Sep 13, 2012 at 22:19
  • I can't see anything that's wrong with the syntax. Can you post the error messages? Commented Sep 13, 2012 at 22:23
  • Hi,sorry but i dont see where i am missed this Commented Sep 13, 2012 at 22:25

3 Answers 3

1

I would rewrite the whole outside block. Instead do:

 <? if( isset($_POST['send'])&&  !validateDiscp($_POST['Discp']) || !validateSize($_POST['Size']) ) { ?>
        <div id="error">
            <ul>
               <?php if(!validateDiscp($_POST['Discp'])) { ?>
                    <li><strong>Discription:</strong> Discription need to be larger then 10!</li>
                <?php } ?>
                <?php if(!validateSize($_POST['Size'])) { ?>
                    <li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
                <?php } else { 
        $nothing = true;
                 ?>



            </ul>
        </div>

    <?php if( isset( $nothing ) and isset($_POST['send'] ) ) { ?>
        <div id="error" class="valid">
            <ul>
                <li><strong>Congratulations!</strong> All fields are OK ;)</li>
            </ul>
        </div>

     <? } ?>

I think the flaw in your logic ist hat you have an else statement that is dangling. Instead add a little logic to detect when the else case is hit and add your additional logic and your good to go.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi there I need to explain a bit the behavior expected: This code need to check 1st if the from is sent if yes he checks if the functions: validateSize and validateDiscp are false if yes he need to show message o1 or 2 if it is sent and functions return true he show message 3 If it is not sent it no thing is showed.
1

All the endifs need to have ; after them. Also, I'm not sure if this is an actual error or just the code getting wrapped, but make sure your first if is all on one line.

2 Comments

Some one have an other idea ???? i tink that the is that isset($_POST['send2']) is alwiase true
OK, then I'd need to see the HTML for the form.
0

after changing things it is working here is the code

        <?php if(isset($_POST['send']) && !validateDiscp($_POST['Discp'])|| !validateSize($_POST['Size'])  ):?>

    <div id="error">
                <ul>
                    <?php if(!validateDiscp($_POST['Discp'])):?>
                        <li><strong>Discription:</strong> Discription need to be larger then 10!</li>
                    <?php endif;?>
                    <?php if(!validateSize($_POST['Size'])):?>
                        <li><strong>Invalid Size:</strong> Size needs to bi S M L XL</li>
                    <?php endif; ?>



                </ul>
            </div>
    <?php elseif(isset($_POST['send']) ):?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.