How do I make a selection of a drop down menu in another page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sam Helmy
    New Member
    • Sep 2010
    • 2

    How do I make a selection of a drop down menu in another page?

    I need people to go through a table of courses and when they find the course they want, they can click a "submission " or "registrati on" button which will automatically take them to the registration form (another php page) where they can fill in their details to be emailed to us, and have the course already selected from a drop-down menu that holds all courses.

    How do I do that using javascript or html or php?

    I don't have MYSQL, databases, or sessions so security is not a big issue, and my programming skill is not that great so please tell me exactly what I need to write, and what variables should I be substituting in the code.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    You don't have a database, yet you are making an application with courses? Are you serious?

    Anyway, if you WERE using a database, every course would have a unique ID. When someone registers, they could either have that course already selected from a <select> element using that ID, or they wouldn't need a <select> element at all since you already sent the ID to the form.


    Course page:
    Code:
    <h1>Course #XXX: Course Name<h1>
    <p>Course details...</p>
    <p>Would you like to register for this course?</p>
    <a href="register.php?id=XXX">Register</a>

    Registration page:
    Code:
    <?php $errors = array();
    $success = false;
    
    if (!empty($_POST) && isset($_GET['id'])) {
      // Validate form data
      if (empty($_POST['name'])) {
        $errors[] = 'Name must be filled.';
      }
    
      // Sign up user
      if (empty($errors)) {
        $name = $_POST['name'];
        $course = $_GET['id'];
        // Save the user's registration via the above information
        // Then e-mail it to whoever cares
        $success = true;
      }
    } ?>
    
    <?php if ($success): ?>
    <p class="success">You are now registered for course #<?php echo $_GET['id']; ?>.</p>
    <?php else: ?>
    <?php if (!empty($errors)): ?>
    <p class="errors">Errors: <?php echo implode("<br />\n", $errors); ?></p>
    <?php endif; ?>
    <form method="post">
      <label for="name">Name:</label>
      <input type="text" name="name" />
      <button type="submit">Register</button>
    </form>
    <?php endif; ?>

    Comment

    • Sam Helmy
      New Member
      • Sep 2010
      • 2

      #3
      Thanks for this.

      Yes I am using a simple array to hold the courses list in the registration form. It already has validations and the array built in.

      How would I do this?

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        If the courses are in an array, then their "ID" would be their array key. Then, just apply the code I provided.

        Comment

        Working...