Jump to content

Return form if no option has been selected


mikebyrne

Recommended Posts

At present my form loads and displays all goods "Games" from the database. If the user want to edit the detail the user selects the relevent radiobutton and presses edit

 

However, at present I have no validation to return the form if the user selects NO option and presses Edit

 

How can I code this validation??

 

<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>

 

 

Link to comment
Share on other sites

You also don't have a form, so right now this page should do nothing.

 

You have two options: PHP or Javascript. The javascript method will allow you to check right then-and-there to see if any of the radio buttons is checked, and would be something to the effect of getting the element by id and seeing if it's value is something other than null. You would run this with an onClick function on your button.

 

The PHP method would have you put a check at the top of your processing form that sees if the $_POST['something'] equals anything other than NULL. If it equals NULL, echo out an error message or redirect back to your menu page.

Link to comment
Share on other sites

My complete code is actally:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->


</div>

</div>
</body>
</html>

 

I like the sound of the javascript option but i've no idea how to code it

Link to comment
Share on other sites

My complete code is actally:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->


</div>

</div>
</body>
</html>

 

I like the sound of the javascript option but i've no idea how to code it

 

Check this page, mate:

 

http://www.codeave.com/javascript/code.asp?u_log=7049

Link to comment
Share on other sites

Looks very good, but I wouldnt have a clue where to start in terms of putting my code with that.

 

Think I'll have to find the javascript section for this one !!

 

I think I don't understand what you mean... the example shows complete HTML file so you can see where it is put.

Link to comment
Share on other sites

In my case each radio button is generated by a loop so a little confused as to how i would name the radio buttons etc?

 

Also how would I rename the form line below etc like your example as I use "something" in edit.php, the page that my edit button refers too

 

  <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>

 

Link to comment
Share on other sites

Here's a trick I use in my coding to keep related stuff all in the same file:

 

<?php
  //$_REQUEST['data'] matches against the name in the <input> tag.
  $data = $_REQUEST['data'];
  $enter = $_REQUEST['enter'];

  //has form been submitted? 
  //with simple radio buttons, !$data is enough to see that something has been selected. 
  //with other types of of inputs, you can put in more advanced error checking.
  if ((!$enter) || (!$data)) {
    //display form...
    echo "<form action=''>
      <input name='data' type='radio' value='SomeValue' />SomeValue
      <input name='data' type='radio' value='SomeOtherValue' />SomeOtherValue
      <input name='enter' type='hidden' value='yup' />
      <input name='submit' type='submit' value='Edit' />";
    exit();
  }

  //handle form data...
  echo "Check out my data: $data";
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.