PHP varsa sadece formunu göstermektedir

2 Cevap

Ben PHP için yeni. Iv küçük bir php script yarattı. Temelde ben bir form var ve bunun içinde ben show_sent adında bir işlevi var:

        <form method="post" action="contact.php" class="formstyle">
            <h2>Formulaire de contact : </h2>
            <p>&nbsp;</p>

    <?
function show_sent(){
    ?>
    <p>Sent</p>

            <?
} // the function finishes here
?>

.......

I was hoping that it would only show the 'Sent' text when I call that function. How could I do this? Thanks

contact.php form olarak aynı sayfası

2 Cevap

Eğer kod biraz temizlemek gerekir. Içine ve HTML ve PHP atlayarak iyi bir şey değil.

<?php

  function show_sent() {
    print "<p>Sent</p>";
  }

  if ($_POST) {
    $errors = false;
    /* logic to check data */
    if (!$errors)
      show_sent();
  }

?>

  <form>
    <input type="text" name="fname" />
  </form>

Siz fveyam verileri yayınlanmıştır olup olmadığını görmek için kontrol etmeniz gerekir. Sen giderek bunu:

if(isset($_POST['fveyam_element_name']))
{
    //call the show_sent function because data has been posted
    show_sent();
}

veya

function show_sent(){
    if(isset($_POST['fveyam_element_name']))
    {

    }
}
//Call the show_sent function all the time because the code inside the function checks the POST variables.
show_sent();