?
Solved

Determining value of secondary input based upon primary

Posted on 2016-08-18
2
Medium Priority
?
41 Views
Last Modified: 2016-08-31
Okay, so I've got a stupid question.  Here's a model of what I'm working with.

https://jsfiddle.net/5bxjxwj4/2/

There's a webform that's dynamically created based upon database entries (course 1, course 2, ... course X).  The user selects the a number of tickets based upon the select next to the price.

What would be the best way of determining which price has been selected on form submission?
0
Comment
Question by:erzoolander
2 Comments
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 41761577
First problem - duplicate id's - id's must be unique on the page.
Second problem - duplicate names - the second one will overwrite the first ... actually the submission will be something like
adnum_1=4&adnum_1=2

Open in new window

But even if you process the raw POST you can't tell which is which.

Just give your selects different names like
adnum_68 and adnum_70
That way you can check the values of those variables when they are submitted to see how many of each ticket was requested.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 41762481
A general design for something like this would be a "Course Object."  This object would live in your database (probably in an active record design).  Each Course would be represented by one object.  The object would have associated information about the course, for example, its "id" and title, cost, duration, schedule, number of seats, number of available seats, etc.

The PHP script that builds the HTML form would use the Course Object to create the HTML.  Since the course "id" is unique, it can be used as a suffix for the form input control names.  This will give you a way to get names like adnum_68  and adnum_70  as Julian suggests.

If you're getting into course and class scheduling, the fundamentals of a "resource scheduling calendar" will come into play.  This article contains an example showing the design we use to schedule finite resources.  See Practical Application #12.
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question