Solved

Making a drop down box in a form sticky.

Posted on 2008-06-21
6
847 Views
Last Modified: 2008-09-24
HI there I have two drop down boxes. One to select the time and another to select the price of an event.

Basically I want them to be sticky so if the form is submitted and there is a mistake I want the form to remeber the value.

I've included two parts to my script the

the drop down boxes:

Event start time:<select name="eventtime">
 
<option value="00:00:00">00:00</option>
<option value="00:30:00">00:30</option>
<option value="01:00:00">01:00</option>
<option value="01:30:00">01:30</option>
<option value="02:00:00">02:00</option>
<option value="02:30:00">02:30</option>
<option value="03:00:00">03:00</option>
<option value="03:30:00">03:30</option>
<option value="04:00:00">04:00</option>
 
<option value="04:30:00">04:30</option>
<option value="05:00:00">05:00</option>
<option value="05:30:00">05:30</option>
<option value="06:00:00">06:00</option>
<option value="06:30:00">06:30</option>
<option value="07:00:00">07:00</option>
<option value="07:30:00">07:30</option>
<option value="08:00:00">08:00</option>
<option value="08:30:00">08:30</option>
 
<option value="09:00:00">09:00</option>
<option value="09:30:00">09:30</option>
<option value="10:00:00">10:00</option>
<option value="10:30:00">10:30</option>
<option value="11:00:00">11:00</option>
<option value="11:30:00">11:30</option>
<option value="12:00:00">12:00</option>
<option selected="selected" value="">SELECT</option>
<option value="12:30:00">12:30</option>
 
<option value="13:00:00">13:00</option>
<option value="13:30:00">13:30</option>
<option value="14:00:00">14:00</option>
<option value="14:30:00">14:30</option>
<option value="15:00:00">15:00</option>
<option value="15:30:00">15:30</option>
<option value="16:00:00">16:00</option>
<option value="16:30:00">16:30</option>
<option value="17:00:00">17:00</option>
 
<option value="17:30:00">17:30</option>
<option value="18:00:00">18:00</option>
<option value="18:30:00">18:30</option>
<option value="19:00:00">19:00</option>
<option value="19:30:00">19:30</option>
<option value="20:00:00">20:00</option>
<option value="20:30:00">20:30</option>
<option value="21:00:00">21:00</option>
<option value="21:30:00">21:30</option>
 
<option value="22:00:00">22:00</option>
<option value="22:30:00">22:30</option>
<option value="23:00:00">23:00</option>
<option value="23:30:00">23:30</option>
</select> Entry price:<select name="eventprice">
<option selected="selected" value="">SELECT</option>
<option value="Free">Free</option>
<option value="£1">£1</option>
 
<option value="£2">£2</option>
<option value="£3">£3</option>
<option value="£4">£4</option>
<option value="£5">£5</option>
<option value="£6">£6</option>
<option value="£7">£7</option>
<option value="£8">£8</option>
<option value="£9">£9</option>
<option value="£10">£10</option>
 
<option value="£11">£11</option>
<option value="£12">£12</option>
<option value="£13">£13</option>
<option value="£14">£14</option>
<option value="£15">£15</option>
<option value="£16">£16</option>
<option value="£17">£17</option>
<option value="£18">£18</option>
<option value="£19">£19</option>
 
<option value="£20">£20</option>
<option value="£25">£25</option>
<option value="£30">£30</option>
<option value="£40">£40</option>
<option value="£50">£50</option>
</select>

(sorry for the length)

and the php validation as a code snippet

Thanks in advance,

Daniel
if (!empty($_POST['eventtime'])) {
  $etm = escape_data($_POST['eventtime']);
 
} else {
 
  $etm = NULL;
  echo '<p><font color="red" size="+1">Please enter a time for the event.</font></p>';
  
}
 
// Check for entry price
 
if (!empty($_POST['eventprice'])) {
  $epr = escape_data($_POST['eventprice']);
 
} else {
 
  $epr = NULL;
  echo '<p><font color="red" size="+1">Please enter a price for the event.</font></p>';
  
}

Open in new window

0
Comment
Question by:dm404
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:afzz
ID: 21836898
try this
Event start time:<select name="eventtime">
 
<option value="00:00:00">00:00</option>
<option value="00:30:00">00:30</option>
<option value="01:00:00">01:00</option>
<option value="01:30:00">01:30</option>
<option value="02:00:00">02:00</option>
<option value="02:30:00">02:30</option>
<option value="03:00:00">03:00</option>
<option value="03:30:00">03:30</option>
<option value="04:00:00">04:00</option>
 
<option value="04:30:00">04:30</option>
<option value="05:00:00">05:00</option>
<option value="05:30:00">05:30</option>
<option value="06:00:00">06:00</option>
<option value="06:30:00">06:30</option>
<option value="07:00:00">07:00</option>
<option value="07:30:00">07:30</option>
<option value="08:00:00">08:00</option>
<option value="08:30:00">08:30</option>
 
<option value="09:00:00">09:00</option>
<option value="09:30:00">09:30</option>
<option value="10:00:00">10:00</option>
<option value="10:30:00">10:30</option>
<option value="11:00:00">11:00</option>
<option value="11:30:00">11:30</option>
<option value="12:00:00">12:00</option>
<option selected="selected" value="<?=$etm==""?"":"$etm"?>"><?=$etm==""?"SELECT":"$etm"?></option>
<option value="12:30:00">12:30</option>
 
<option value="13:00:00">13:00</option>
<option value="13:30:00">13:30</option>
<option value="14:00:00">14:00</option>
<option value="14:30:00">14:30</option>
<option value="15:00:00">15:00</option>
<option value="15:30:00">15:30</option>
<option value="16:00:00">16:00</option>
<option value="16:30:00">16:30</option>
<option value="17:00:00">17:00</option>
 
<option value="17:30:00">17:30</option>
<option value="18:00:00">18:00</option>
<option value="18:30:00">18:30</option>
<option value="19:00:00">19:00</option>
<option value="19:30:00">19:30</option>
<option value="20:00:00">20:00</option>
<option value="20:30:00">20:30</option>
<option value="21:00:00">21:00</option>
<option value="21:30:00">21:30</option>
 
<option value="22:00:00">22:00</option>
<option value="22:30:00">22:30</option>
<option value="23:00:00">23:00</option>
<option value="23:30:00">23:30</option>
</select> Entry price:<select name="eventprice">
<option selected="selected" value="<?=$epr==""?"":"$epr"?>"><?=$epr==""?"SELECT":"$epr"?></option>
<option value="Free">Free</option>
<option value="£1">£1</option>
 
<option value="£2">£2</option>
<option value="£3">£3</option>
<option value="£4">£4</option>
<option value="£5">£5</option>
<option value="£6">£6</option>
<option value="£7">£7</option>
<option value="£8">£8</option>
<option value="£9">£9</option>
<option value="£10">£10</option>
 
<option value="£11">£11</option>
<option value="£12">£12</option>
<option value="£13">£13</option>
<option value="£14">£14</option>
<option value="£15">£15</option>
<option value="£16">£16</option>
<option value="£17">£17</option>
<option value="£18">£18</option>
<option value="£19">£19</option>
 
<option value="£20">£20</option>
<option value="£25">£25</option>
<option value="£30">£30</option>
<option value="£40">£40</option>
<option value="£50">£50</option>
</select>

Open in new window

0
 

Author Comment

by:dm404
ID: 21837093
Hi afzz,

The code above brings about an error. The error says that $epr and $etm are undefined variables.

It may need an if (isset($_POST['eventdate'] sort of clause?

Thanks in advance!

Daniel
0
 
LVL 4

Expert Comment

by:afzz
ID: 21837249
at the top of your script initialize the variables as shown below and try

$etm = "";
$epr = "";
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:dm404
ID: 21837304
HI afzz,

it still says there is an error in defining the variables :(

This is how I defined the variables

// Check for event time

if (!empty($_POST['eventtime'])) {
  $etm = escape_data($_POST['eventtime']);

} else {

$etm = "";

  echo '<p><font color="red" size="+1">Please enter a time for the event.</font></p>';
 
}

// Check for entry price

if (!empty($_POST['eventprice'])) {
  $epr = escape_data($_POST['eventprice']);

} else {

$epr = "";
  echo '<p><font color="red" size="+1">Please enter a price for the event.</font></p>';
 
}
0
 
LVL 4

Accepted Solution

by:
afzz earned 500 total points
ID: 21837809
The code if (!empty($_POST['eventtime'])) { is within a condition. That is only if there has been a post to the script this is initialized

your code above will not initialize the variables unless there is a post action to the script.

Therefore above everything else add this.

$etm = "";
$epr = "";
and after that add

if (!empty($_POST['eventtime'])) {
......
0
 

Author Comment

by:dm404
ID: 21840145
Hi Afzz,

It is still coming up with the same error even though I set the variables above the condition : s.

Thanks again,

Dan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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…

737 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