SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Custom Error message not showing up

    Hello PHP friends!

    I'm working on a Terms and Conditions page for a survey. Radio buttons are at the bottom of the page to accept or decline the Terms and Conditions.

    When the form is sent, the page is reloaded with the values passed through POST. However, my error message isn't showing up when I attempt to submit without choosing an option. The page reloads with no option selected, so there's no real problem. I just want it to notify the user that they need to make a selection to get anywhere instead of leaving them confused as to why they keep getting taken to the same page over and over again.

    okay, my code is...

    PHP Code:
    <?PHP

    $display_page 
    true;

    if(
    count($_POST) > 0) {
      
    $error_list = array();
      
      
    $consent $_POST['consentoption'];
      
      if(empty(
    $consent))
        {
        
    $error_list[] = 'You did not agree or disagree with the Terms and Conditions of the survey. Please select the appropriate option and click the Take Survey button';
        }
        if(
    count($error_list) == 0)
        {
          if (
    $consent == "Yes")
          {
          
    header('Location: numgen.php');
          }
          elseif (
    $consent == "No")
          {
          
    $status 'Thank you for considering this survey. If you wish to take it, revisit the page and accept the <a href="consent.php">Terms and Conditions</a>.';
          
    $display_page false;
          }
        }
        else {
            
    $status "<h3>Error:</h3>\n";
            
    $status .= "<ul>\n";
            
            foreach(
    $error_list as $error) {
                
    $status .= "<li>$error</li>\n";
            }
            
            
    $status .= "</ul>\n";
        }
    }

    ?>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Survey By Rochelle</title>
        
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="Pragma" content="no-cache" />
        <meta name="distribution" content="global" />
        <meta name="copyright" content="Copyright (c) 2005 TOLS Multimedia. All rights reserved." />
        <meta name="author" content="Clint Rowden 407-681-2263">
        <meta name="robots" content="index, follow" />
        <!-- Design by: Orlando Florida's website design and hosting company - The Outer Limit Studios. 407.681.2263 -->
        <link rel="stylesheet" type="text/css" href="css/surveystyle.css" title="Standard" />
    </head>
    <body>
    <!-- Wrapper DIV -->
    <div id="wrapper">
        <!-- Container DIV -->
    <div id="mainhead">
    </div><!-- END mainhead DIV -->
    <div id="container">
        
        <div id="headcontent">
        <div id="headimg">
        </div><!-- End HeadImg -->
        </div><!-- End HeadContent -->
    </div><!-- End Container -->
    <div id="content">
    <div class="error">
    <?php echo $status?>
    </div>
    <?php if($display_page == true) { ?>
    <h1 class="upper">Survey of the Affects of Ethics Training</h1>
    <h2 class="upper">Certificate of informed consent: Participants of 18 years of age and older</h2>
    <p class="consent">
    I am a student at the University of Phoenix working on a Doctorate Degree in Business Administration. I am conducting a research study titled "The Affects of Ethics Training on Foreign National and American Adults". The purpose of the research study is to explore the affects of ethics training received by certain individuals. The training would be either through getting a degree in higher education or through progressive experience.
    </p>
    <p class="consent">
    Your participation will consist of completing a short demographics survey and a two part questionnaire related to ethics. The entire survey should take no more than 10 to 15 minutes. Your participation is voluntary. A completed response will be considered your consent to take part in the study. If you choose not to take part in or to withdraw from the study, you may do so. Your partial response will not be included in the study.
    </p>
    <p class="consent">
    The study will not include any individual information related to your identity.  The results of the research study may be published but your individual results will remain confidential and anonymous. While there will be no direct benefit to individual participants, the possible benefits of your participation will be to add to the body of knowledge related to the effectiveness and importance of ethics training. Thank you very much for your time and participation.
    </p>
    <p class="consent">
    If you have questions concerning the research study, please contact me at <a href="mailto:rocjones@mail.ucf.edu">rocjones@mail.ucf.edu</a>.
    </p>
    <div id="consentForm">
    <form name="consent" method="post" action="consent.php">
    <input type="radio" name="consentoption" value="Yes" /> I accept the terms and conditions of the study. <br />
    <input type="radio" name="consentoption" value="No" /> I do not accept the terms and conditions and do not wish to participate in the study. <br />
    <input id="submit" type="submit" value="Take Survey" />
    </form>
    </div>
    <?php ?>
    </div><!-- End Content DIV -->

    <div id="footer">
    </div> 
     
    </div><!-- End Wrapper DIV -->

    </body>
    </html>
    Thanks in advance!
    Last edited by crowden; Sep 15, 2006 at 09:26.
    No, I REALLY dislike having to use Joomla.

  2. #2
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, i changed my (count($_POST) > 0) to (isset($_POST)) and my error message pops up, but not like it's supposed to.

    my thought is that way was completely wrong...
    No, I REALLY dislike having to use Joomla.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what do you mean not like its supposed to?

  4. #4
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shows up during the first access of the page instead of waiting until after the form has been posted to show the error.
    No, I REALLY dislike having to use Joomla.

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add a hidden field and test for it
    if (isset($_POST['submitted']))
    that would also have allowed if (count($_POST)) to work properly.

    dont use the submit button to test, because the user may submit the form using the enter key, in which case the name of the submit button may not be sent.

  6. #6
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, I'll give it a shot.

    thanks for the knowledge!
    No, I REALLY dislike having to use Joomla.

  7. #7
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went with

    PHP Code:
    if(count($_POST) > 0
    and added the hidden field. I left the $_POST from the hidden field out of the error array and it worked.

    Does it need to recieve more than one $_POST in order for it to recognize the count?

    Am I way off? and if my lingo isn't correct, please feel free to correct me.

    Thanks clamcrusher
    No, I REALLY dislike having to use Joomla.

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as long as the browser sends at least 1 field via post, this will be true

    if(count($_POST) > 0)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •