Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 21st, 2005, 1:33 PM   #1
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5 bulio is on a distinguished road
Submitting problem

Hi everyone,

I have a product submit form for my company (coded in html). What I would like to do, is that if someone does not fill out all the required fields to submit the product, a php script would tell them something like:

Sorry, you have not filled in $fieldhere. Please go back and fill it in.

This is My current code: (index.htm)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
     <TITLE>Coyote Product Submit Form</TITLE>
</HEAD>

<BODY>
     <H3 ALIGN="center">Coyote website product submit form</H3>

     <FORM ACTION="submit.php" METHOD="POST" ENCTYPE="text/plain">
         <TABLE>
               <TR>
                    <TD>&nbsp;&nbsp;<B>Location of product:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="location">
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Description:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="Description" >
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Make:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="Make" >
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Model:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="Model" >
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Year:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="Year" >
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Color:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="Color" >
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Suggested list price:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="price" VALUE="$0.00" SIZE="16" style="WIDTH: 148px; HEIGHT: 22px" 0.00???>
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Inventory Type:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="InventoryType" style="WIDTH: 155px; HEIGHT: 22px" >
                    <BR>
                    <BR>
                    &nbsp;&nbsp;<B>Serial #:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="Serial" SIZE="22" style="WIDTH: 171px; HEIGHT: 22px">
                    <BR>
                    &nbsp;&nbsp;<B>Name of submitter:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <INPUT NAME="name"></TD>

	       </TR>

               <TR>
                    <TD ALIGN="middle"><INPUT TYPE="submit" VALUE="Submit" STYLE="COLOR: #ffffff; BACKGROUND-COLOR: #000000"></TD>
               </TR>
          </TABLE>
     </FORM><A href="index.htm">Click Here</A> to submit another product to the site.
     <BR>
     <BR>
     <BR>



     <H3 ALIGN="center">Instructions</H3>
     <BR>
     <BR>

     <H5>1: Enter all required information into the text box. Avoid leaving blank spaces.
     <BR>
     <BR>
     2: Once you are completed, press the 'Submit' button. This will then open your e-mail client. Now you should see some text already already in the email.
     <BR>
     <BR>
     3: Now, add an attachment to the email. The attachment should be picture of the object that you want to sell.
     <BR>
     <BR>
     4: Send The email. (It will automatically be sent to the appropriate address)
     <BR>
     <BR>
     5: If you need assistance understanding the text boxes, please visit <A href="submit_help.htm">This Page</A>
     <BR>
     <BR>
     6: The information will soon be added to the site.</H5>
     <BR>

</BODY>
</HTML>

In submit.php:

<?php
 if ( (!empty($location)) && (!empty($Description)) && (!empty($Make)) && (!empty($Model)) && (!empty($Year)) && (!empty($Color)) && (!empty($price)) && (!empty($InventoryType)) && (!empty($Serial)) && (!empty($name)) )
 {
     echo "The product has been submitted ok.";
 }
 else
 {
     echo "You have left a text box blank, please go back and fill it in.";
 }
 ?>

This is the error that I get If I submit it with some fields blank:

Notice: Undefined index: location in c:\program files\easyphp1-8\www\submit.php on line 2
The product has been submitted ok.
bulio is offline   Reply With Quote
Old Jun 21st, 2005, 4:07 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Simple:
[php]$blank_fields = array();
if (empty($_GET['field']))
{
$blank_fields[] = 'Field 1';
}
else if (empty($_GET['another_field']))
{
$blank_fields[] = 'The second field';
}
...
if (count($blank_fields) > 0)
{
echo "You did not fill in the following fields:<br />\n";
foreach ($blank_fields as $field)
{
echo "&nbsp;&nbsp;&nbsp;&nbsp;$field<br />\n";
}
}[/php]

That should do it. Basically, it goes through the fields you want checked, and adds them to an array if they're empty. It then echoes a list if there is one.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 22nd, 2005, 12:08 PM   #3
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5 bulio is on a distinguished road
Now I get this:

Quote:
$blank_fields = array(); if (empty($_GET['field'])) { $blank_fields[] = 'Field 1'; } else if (empty($_GET['another_field'])) { $blank_fields[] = 'The second field'; } ... if (count($blank_fields) > 0) { echo "You did not fill in the following fields:
\n"; foreach ($blank_fields as $field) { echo " $field
\n"; } }
bulio is offline   Reply With Quote
Old Jun 22nd, 2005, 1:12 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
And???
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 22nd, 2005, 1:46 PM   #5
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5 bulio is on a distinguished road
It doesn't work, that is what it outputs if fields are left blank.
bulio is offline   Reply With Quote
Old Jun 22nd, 2005, 1:50 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You did change the fields to the respective field names, right?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC