www.webdeveloper.com
Results 1 to 5 of 5

Thread: Condition Checking

  1. #1
    Join Date
    Mar 2005
    Posts
    172

    Condition Checking

    Hi All,

    I've created a form, whereby if fields are not filled in then the form should not be processed:

    PHP Code:
    <?php

    // ** If Submit is hit do your stuff **
        
    if (isset($_POST['Submit'])) {
        
         
    $your_name $_POST['your_name'];
         
    $your_email $_POST['your_email'];

    // ** Check for Required Fields with IF statements **
           
    if (empty($your_name)){
            
    $error "** You forgot to enter your name! **"
        }  else if (empty(
    $your_email)){
            
    $error "** Error: You forgot to enter your email! **";
        } 
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Submit_test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form action="process_submission.php" method="POST" enctype="multipart/form-data">
    <?php echo $error?>
      <table width="475" border="0" cellpadding="0" cellspacing="5" bgcolor="FFFFFF">
        <tr> 
          <td colspan="2" class="formtext"><strong>Personal Details</strong></td>
        </tr>
        <input type=hidden name=subject value="News Submission Form">
        <tr> 
          <td width="239" align="left" valign="middle" class="formtext">Name:</td>
          <td align="left" valign="middle"> <INPUT TYPE="text" NAME="your_name"></td>
        </tr>
        <tr> 
          <td class="formtext">Address:</td>
          <td><INPUT TYPE="text" NAME="your_address"> </td>
        </tr>
        <tr> 
          <td> </td>
          <td><input type="submit" name="Submit" value="Submit"> </td>
        </tr>
      </table>
          </form>
    </body>
    </html>
    However, it seems to ignore my rules I created and just proceed to the next page?

    Any help please?

    Thanks

    Chris

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    Is this the code for the page process_submission.php or is process_submission.php a separate page?

  3. #3
    Join Date
    Oct 2005
    Location
    Philadelphia, USA
    Posts
    74
    Yeah, this I agree with aj_nsc, your post is confusing.

    It looks like you might be trying to do client side validation with php.

    There are two ways to validate forms. On the client side using javascript or the server side using php.

    If you want to validate a form before submission use javascript. If you want to check a form after submission and then return to the form if there are erros, use php.

  4. #4
    Join Date
    Mar 2005
    Posts
    172
    Hi,

    It's using two pages in php. Basically here's the workflow:

    1) User enters the details on that first page (ie page.php)
    2) The page then checks the conditions
    3) If they are true go to process_submission.php
    4) If these are not true echo an $error

    Thanks

    Chris

  5. #5
    Join Date
    Dec 2005
    Posts
    2,984
    Your form is not being submitted to page.php (it is being submitted to process_submission.php) and subsequently there will be no error handling. Hope this gave you an epiphany into how PHP works and why yours doesn't....if not, post back and we'll help you out some more.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles