Jump to content

form action query


Don the dragon

Recommended Posts

Hi

I have a bit of a  problem that I cant sort out (a newbie thing).

I want to submit my form, after it has passed its validation to a 'confirm' page.

Where do I state this, as the action in the form is being used for other purposes.

 

 

<?php

session_start();

$_SESSION['sess']=session_id();

 

require_once('includes/recaptchalib.php');

$publickey = "6LeX0gIAAAAAAHQ9qrhR9otZToT2ttxPCgmtnGSs"; // you got this from the signup page

//echo recaptcha_get_html($publickey);

?>

<?php

if (array_key_exists('submit', $_POST)) {

// validate the input, beginning with name

  $name = trim($_POST['name']);

  if (empty($name)) {

    $error['name'] = '*';

    }

  $contact = trim($_POST['contact']);

  if (empty($contact)) {

    $error['contact'] = '*';

    }

  $email = $_POST['emailaddress'];

  // check for valid email address

  $pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';

  if (!preg_match($pattern, trim($email))) {

    $error['emailaddress'] = '*';

    }

  // check the content of the text area

  $comments = trim($_POST['comments']);

  if (empty($comments)) {

    $error['comments'] = '*';

    }

}

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Contact Us</title>

</head>

 

<body>

<div id="wrapper">

    <div id="main_pic">

    <?php if ($error) { ?>

        <h2>Please correctly fill in all fields</h2>

        <?php } else { ?>

<h2>Contact us</h2>

        <?php } ?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" id="booking" name="booking">

<fieldset>

        <legend>Contact Details</legend>

            <label for="name">Full name :</label>

            <input name="name" type="text" id="name" <?php if(isset($error)) {echo "value='$name'";} ?> /><?php if (isset($error['name'])) { ?>

                <span class="warning"><?php echo $error['name']; ?></span>

                <?php } ?>

                <br />

            <label for="contact">Contact number :</label>

            <input name="contact" type="text" id="contact" <?php if(isset($error)) {echo "value='$contact'";} ?> /><?php if (isset($error['contact'])) { ?>

                <span class="warning"><?php echo $error['contact']; ?></span>

                <?php } ?>

                <br />

            <label for="emailaddress">E-mail address :</label>

            <input name="emailaddress" type="text" id="emailaddress" <?php if(isset($error)) {echo "value='$email'";} ?> /><?php if (isset($error['emailaddress'])) { ?>

                <span class="warning"><?php echo $error['emailaddress']; ?></span>

                <?php } ?>

                <br />

            <label for="comments">Comments :</label>

            <textarea name="comments" cols="30" rows="5" id="comments"><?php if(isset($error)) {echo $comments;} ?></textarea><?php if (isset($error['comments'])) { ?>

                <span class="warning"><?php echo $error['comments']; ?></span>

                <?php } ?>

                <br />

                <br />

                <div id="capcha_block"><?php echo recaptcha_get_html($publickey); ?></div>

            <input type="submit" name="submit" value="submit" class="button_one" />

            <input type="reset" name="reset" value="start over" class="button_one" />

    </fieldset>

</form> 

  </div>

</div>

</body>

</html>

 

Cheers

Donovan

Link to comment
https://forums.phpfreaks.com/topic/132535-form-action-query/
Share on other sites

<?php
   if (array_key_exists('submit', $_POST)) {    
      // validate the input, beginning with name
       ..........................
..................................
        $email = $_POST['emailaddress'];
        // check for valid email address
        $pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
        if (!preg_match($pattern, trim($email))) {
          $error['emailaddress'] = '*';
       }
        // check the content of the text area
        $comments = trim($_POST['comments']);
        if (empty($comments)) {
          $error['comments'] = '*';
       }




if(!$error)
  {
  header("location:yourpage.php");
  
  }

   }
   
?>

Link to comment
https://forums.phpfreaks.com/topic/132535-form-action-query/#findComment-689174
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.