SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27
  1. #26
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From everything I have Googled and read about you cannot have 2 php actions in a form. I don’t want my HTML code to be any longer than it currently is so I thought it might be a great idea to incorporate the original send.php with processform.php (validation code) .

    The problem is if my fields are empty when I submit the form I don’t receive any error messages and emails go out blank like so - and I receive Thank you message.
    Stock Number:
    Serial Number:
    Description:
    Etc.

    I tested my processform.php by itself for the first 5 fields, which are text fields and did receive errors when blank. However, when I added the drop downs I didn’t get errors.

    I thought why not try to merge the two php files together but that isn’t working either. Hmmmm – I’m at a loss and I can't seem to attach code, I keep getting 500 Internal error code.

  2. #27
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    /*
    * BEGIN CONFIG - processform validation code
    */

    // The page you want the user to be redirected if there are no errors.
    $thankYouPage = 'thanks.html';

    // Define which values we are to accept from the form. If you add additional
    // fields to the form, make sure to add the form name values here.
    $allowedFields = array(
    'stockNumber',
    'serialNumber',
    'description',
    'requestedBy',
    'requestedDate',
    'custInfo',
    'R_branch',
    'S_branch',
    );

    // Specify the required form fields. The key is the field name and the value
    // is the error message to display.
    $requiredFields = array(
    'stockNumber' => 'Stock Number is required.',
    'serialNumber' => 'Serial Number is required.',
    'description' => 'Description is required.',
    'requestedBy' => 'Requested By is required.',
    'requestedDate' => 'Please select a Requested Date.',
    'custInfo' => 'Customer Information is required.',
    'R_branch' => 'Please select Requesting Branch.',
    'S_branch' => 'Please select Shipping Branch.',

    );

    /*
    * BEGIN FORM VALIDATION
    */

    $errors = array();

    // We need to loop through the required variables to make sure they were posted with the form.
    foreach($requiredFields as $fieldname => $errorMsg)
    {
    if(empty($_POST[$fieldname]))
    {
    $errors[] = $errorMsg;
    }
    }

    // Loop through the $_POST array, to create the PHP variables from our form.
    foreach($_POST AS $key => $value)
    {
    // Is this an allowed field? This is a security measure.
    if(in_array($key, $allowedFields))
    {
    ${$key} = $value;
    }
    }

    /*
    * END FORM VALIDATION
    */

    // Were there any errors?
    if(count($errors) > 0)
    {
    $errorString .= '<ul>';
    foreach($errors as $error)
    {
    $errorString .= "<li>$error</li>";
    }
    $errorString .= '</ul>';

    // display the errors on the page
    ?>
    <html>
    <head>
    <title>Error Processing Form</title>
    </head>
    <body>
    <h2>Error Processing Form</h2>
    <p>There was an error processing the form.</p>

    <p><a href="transfer.html">Go Back to the Form</a></p>
    </body>
    </html>
    Last edited by sparkymom7; Jul 8, 2013 at 08:13. Reason: Unable to add PHP code


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
  •