Solved

Making a drop down box in a form sticky.

Posted on 2008-06-21
6
842 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
  • 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

831 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