Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
two page form handling with validation?
Old 08-05-2008, 04:50 PM two page form handling with validation?
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
I'm thinking about having a contact form on my "contact_form_page.php" that submits the form data to another page: the "form_processing.php" page. But if the form validation on "form_processing.php" comes up with errors, I want it to seem to the user that they have never really left the "contact_form_page.php" and that error messages show up on that page, e.g. "Please enter a valid e-mail address", "please enter an organization name" and then they can continue to fill out the contact form as if they have never left the "contact_form_page.php". Then, finally, when they have successfully sent the form, I would like to erase the form from the page and replace it with a detailed confirmation message, like: "Thank you name, your message, message, message, message has been successfully sent." Will this strategy work with two pages involved or should I do all the scripting on one page?

Many thanks,

matt
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
 
Register now for full access!
Old 08-05-2008, 05:14 PM Re: two page form handling with validation?
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
You should put the processing above the header in the page the forms on. When you're parsing through your form elements and encounter an error, do:

PHP Code:
$error[] = "Name not long enough"
When it comes to submitting all the processed form data do:

PHP Code:
if(!isset($error)) {
// Your processing code, mail()?? mysql_query()??

to check there's no errors, maybe redirect when its done.

PHP Code:
if(isset($error)){ print "<div class=\"error\">";
$count 1;
foreach(
$error as $value){
print 
"$count$value<br />";
$count ++;
}
print 
"</div>"; } 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 08-06-2008, 11:28 AM Re: two page form handling with validation?
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
galaxian,

Woops! I don't know how I resent my old post.

Do you know how to integrate a ReCaptcha into a single page form processing? I can make it work with two separate files, but not on one page. I need to do this before I can use your already offered coding help. Here is my code so far:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Contact Form</title>
<meta http-equiv="Content-Type"
   content="text/html; charset=iso-8859-1">
</head>
<body>
 <?php
  if ($_SERVER['REQUEST_METHOD'] != 'POST'){
  $me = $_SERVER['PHP_SELF'];
  ?>
   <form name="form1" method="post"
         action="<?php echo $me;?>">
      <table border="0" cellspacing="0" cellpadding="2">
         <tr>
            <td>Name:</td>
            <td><input type="text" name="Name"></td>
         </tr>
         <tr>
            <td>Subject</td>
            <td><input type="text" name="Subject"></td>
         </tr>
         <tr>
            <td valign="top">Message:</td>
            <td><textarea name="MsgBody"></textarea></td>
         </tr>
  <tr>
  <td>
         <?php
   require_once('recaptchalib.php');
   $publickey = "6LeLTQEAAAAAAFwsoz6WomDxk0Mrs9MEaNOPgOc6"; // you got this from the signup page
   echo recaptcha_get_html($publickey);
   ?>
  </td>
        </tr>
         <tr>
            <td><input type="submit" name="Submit"
               value="Send"></td>
         </tr>
      </table>
   </form>
   <?php
/* insert recaptcha code here?
require_once('recaptchalib.php');
$privatekey = ".........";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
*/
      } else {
         error_reporting(0);
         $recipient = 'end user';
         $subject = stripslashes($_POST['Subject']);
         $from = stripslashes($_POST['Name']);
         $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
         if (1 == 1)
            echo nl2br("<b>Message Sent:</b>
            To: $recipient
            Subject: $subject
            Message:
            $msg");
         else
            echo "Message failed to send";
   }
?>
 
</body>
</html>
 
Things work fine until I activate the php code that's commented out then it breaks. Is there a site that shows how to do ReCaptcha on one page? The site I found "Inco9nito" only demonstrates how to do a ReCaptcha on two pages.

Thanks again,
matt w
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
Reply     « Reply to two page form handling with validation?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12891 seconds with 12 queries