Results 1 to 12 of 12

Thread: Send form to two places to capture data from a user registration form?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Send form to two places to capture data from a user registration form?

    Hello Folks,

    Can somebody help me out please?

    I want to create a registration form so that when a use clicks send, it will go to two different applications. I do not really know if this is possible or I am doing it right. I will appreciate any help and suggestion you can give please.

    The task is, when a user clicks send after filling the form, one application will retrive some part of the data (eg firstname, lastname, age, etc) and the other will also retrive some part of the data (also firstname, lastname, age, etc). Is there a way of capturing user registration form values on submission, please?

    You can see the files i am currently using.
    My MySQL database code and the PHP code are below.

    When I fill and test the form, I get the error message 'subscription' was empty and 'attendance was empty' even when they are both checked.

    Or when the form gets sent to the database, values for age, subscription, gender and attendance are empty. I don't know if it is because of the checkbox, radiobutton and select menu that I have in those fields.

    I would want the form to go two two different places, that is the data on the form will be captured in two places. One place is a web application while the other is an API.

    Can this be achived with one form or do I need two forms?

    I hope it makes sense what I am aiming at.

    The code for my database
    Code:
    create table players(
    fname          VARCHAR(25),
    lname          VARCHAR(25),
    email          VARCHAR(60),
    age            VARCHAR(8),
    city           VARCHAR(20),
    gender         CHAR(1),
    subscription   CHAR(1),
    phone          VARCHAR(20),
    hobbies        VARCHAR(25),
    attendance     CHAR(1)
    );
    The code for my php page
    Code:
    <?php 
    //here we set our database log in details.
     $hostname = "localhost";
     $username = "root";
     $password = "";
     
    //connection to t he database with  details set above
    //if the connections fail, it will show us errors
     $link = mysql_connect($hostname,$username,$password);
              if(!$link)
    		  {die("No Database connection" .mysql_error());
    		  }
       
    //here we select a database to use. 
    //If the link fails, show the message below and tell us why.
       $selected = mysql_select_db("members",$link)
         or die("I cannot find that database" .mysql_error());
    ?> 
    
    
    <!doctype html>
    <html>
    <head>
    <style type="text/css"> p {margin: 0px;}</style>
    <meta charset=utf-8>
    <title>Form data entry validation and capturing </title>
    </head>
    
    <body>
    <h1>User registration form</h1>
    <h2>Please complete the form below</h2>
       <?php
    //we should always show the form unless the data is incomplete
      $formdisplay = true;
    
    //initialize the error array
        $errors = array();
    
    //has this form been submitted?
      if($_SERVER['REQUEST_METHOD'] == "POST"){
    
    //loop through $_POST to check if any values were empty
        foreach($_POST as $key => $value){
          if(strlen(trim($value)) == 0) $errors[] = "{$key} was empty";
        }
    
    //if the $errors array is empty, we can proceed
        if(!count($errors)){
          //the data was validated, we don't want to show the form now
          $formdisplay = false;
          
    //entering data into the database
          $fname  = mysql_real_escape_string($_POST['fname']);
    	  $lname  = mysql_real_escape_string($_POST['lname']);
          $email  = mysql_real_escape_string($_POST['email']);
          $age    = mysql_real_escape_string($_POST['age']);
    	  $city   = mysql_real_escape_string($_POST['city']);
    	  $gender = mysql_real_escape_string($_POST['gender']);
    	  $subscription = mysql_real_escape_string($_POST['subscription']);
          $phone  = mysql_real_escape_string($_POST['phone']);
    	  $hobbies = mysql_real_escape_string($_POST['hobbies']);
    	  $hobbies = mysql_real_escape_string($_POST['attendance']);
    
          mysql_query("INSERT INTO `players` VALUES ('$fname', '$lname', '$email', '$age', '$city', '$gender','$subscription','$phone','$hobbies', '$attendance')");
    
        }
      }
    
      if($formdisplay):
    //yes! We can show the form now.
    
    //are there any errors?
        if(count($errors)):
    ?>
    <blockquote>
      <h3>There were errors with your form please:</h3>
    <!---We use a foreach to check for errors and show them--->
      <ul>
    <?php foreach($errors as $error): ?>
        <li><?php echo $error; ?></li>
    <?php endforeach; ?>
      </ul>
    </blockquote>
    <?php endif; ?>
    <!--our form goes in here! We can use CSS to style it -->
    
      <form method="post" />
        <p>First name: &nbsp;<input type="text" size="50" name="fname" value="<?php echo htmlentities(@$_POST['fname']); ?>"/></p> <br />
        <p>Last name: <input type="text" size="50" name="lname" value="<?php echo htmlentities(@$_POST['lname']); ?>"/></p> <br />
        <p>Email: &nbsp; &nbsp;<input type="text" size="50" name="email" value="<?php echo htmlentities(@$_POST['email']); ?>"/></p> <br />
        <p>Age: <select name="agegroup" value="<?php echo htmlentities(@$_POST['age']); ?>">
          <option value="select">Select</option>
          <option value="u18">Under 18</option>
          <option value="o18">Over 18</option>
        </select></p><br/> 
        <p>City: <input type="text" size="50" name="city" value="<?php echo htmlentities(@$_POST['city']); ?>"/></p>  <br />
        <p>Gender: <select name="sex" value="<?php echo htmlentities(@$_POST['gender']); ?>">
          <option value="select">Select</option>
          <option value="male">M</option>
          <option value="female">F</option>
        </select></p><br/>    
        <p>Tick this box to subscribe to our monthly promos: <input type="checkbox" name="subscription" value="<?php echo htmlentities(@$_POST['subscription']); ?>"/></p>  <br />
        <p>Phone: <input type="text" size="50" name="phone" value="<?php echo htmlentities(@$_POST['phone']); ?>"/> </p> <br />
        <p>Hobbies: &nbsp;<input type="text" size="50" name="hobbies" value="<?php echo htmlentities(@$_POST['hobbies']); ?>"/></p> <br />
        
        <p>Morning: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']); ?>"/>
         Afternoon: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']); ?>"/>
         Evening: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']); ?>"/></p> <br /><br/>
    
        <input type="submit" value="Send">
      </form>
    
    <?php else: ?>
    <h1>Message sent successfully!</h1>
    <p>Thanks for registering!</p>
    <?php endif; ?>
    
    <!--I would like to use an API here-->
     </body>
    </html>
    Thanks in advance.
    Last edited by menre; Jun 23rd, 2012 at 04:54 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width