Validate a PHP form w/Javascript? [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snappydesigns
Forum Commoner
Posts: 28
Joined: Tue Feb 13, 2007 11:37 am

Validate a PHP form w/Javascript? [SOLVED]

Post by snappydesigns »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

First off, I have to say that without this forum I would have given up on PHP/MySQL and figured it was just beyond me.  Instead, I've been able to design an e-commerce website with thousands of products.  Thanks to those who have specifically helped me...you know who you are  .

Anyway, I'm back for more help.  As I've said in previous posts, I'm working on a stationery website.  The way I've got the products set up is they are separated by category and then by vendor.  When a vendor's category is clicked, it goes to a page of thumbnails. When a thumbnail is clicked, the customer is brought to the individual product page.  There is an order button on the bottom which will then direct the customer to an order form specifically for that product.  That all works perfectly. 

Now the problem I'm running into is validating the form.  At the very least, the cutomer has to put their contact information (name, email, phone, etc.) before they can submit the form.  In my html based form that customers use for products not directly on the site, I successfully use this Javascript code to validate:

[syntax="javascript"]function form_check(){
    if (!document.getElementById('Name').value){
	alert('Please Enter Your Name');
	return false;
	}
	if (!document.getElementById('Phone').value){
	alert('Please Enter Phone number');
	return false;
	}
	if (!document.getElementById('Address1').value){
	alert('Please Enter Address');
	return false;
	}
	if (!document.getElementById('City').value){
	alert('Please Enter City');
	return false;
	}
	if (!document.getElementById('State').value){
	alert('Please Enter State');
	return false;
	}
	if (!document.getElementById('Zip').value){
	alert('Please Enter Zip');
	return false;
	}
	if (!document.getElementById('Email').value){
	alert('Please Enter E-mail address');
	return false;
	}
	if (!document.getElementById('VendorName').value){
	alert('Please Enter Vendor Name');
	return false;
	}
	if (!document.getElementById('ItemNumber').value){
	alert('Please Enter Item Number');
	return false;
	}
	if (!document.getElementById('FontName').value){
	alert('Please Enter Font Choice');
	return false;
	}
	if (!document.getElementById('Quantity').value){
	alert('Please Enter Quantity');
	return false;
	}
	return true
}
However, the individual product order form is in .php format. Here's my code for that (I hope I'm not over doing it here):[/syntax]

Code: Select all

<?php
include_once 'header.html'; 

// Include a utility fiel 
include_once 'connect_stacy.php';
if (isset($_GET['pid'])) 
{ 
    // it is, so assign the $id var the value of the query string var 'pid' 
    $id = $_GET['pid']; 
    
    // Make a SQL query instruction that pulls columns item_id, 
    // product_name, product_id and image_name from the 
    // donovadesigs table where the item_id value is the same 
    // as the query string pi value 
    $query = 'SELECT item_id, product_id, product_name, item_type, thumb_name, vendor, price1, price2, price3, price4, price5, price6, price7, price8 FROM baby_sta_folds WHERE item_id = ' . $pid; 

    // Execute the query instruction, halt process on query failure 
    $result = mysql_query($query) or die('Could not execute the query: ' . mysql_error()); 
    
    // Assign a one-dimensional, associateive array of the query 
    // result data to $row 
    $row = mysql_fetch_array($result); 

        // if the file_exists() function returns non-false... 
    if ($image = file_exists($row['thumb_name'])) 
    { 
    echo '<table width="746" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">';
      echo '<form name="order" method="post" action="orderprocess_donovan_flats.php">';
      echo '<tr>';
        echo '<td width="45">&nbsp;</td>';
          echo '<td width="289"><h2>ORDER FORM</h2>';
            echo '<h3><font color="#663300">Rather order by phone?</font><br>';
            echo 'Call us at (910) 467-2043.</h3></td>';
          echo '<td width="22">&nbsp;</td>';
            echo '<td width="381"><table width="250" border="0" cellpadding="0">';
              echo '<tr>';
                echo '<td width="141"><p>Item #: ' . $row['product_name'] . '<br>';
                echo ' ' . $row['item_type'] . '<br>';
                echo 'by ' . $row['vendor'] . '</p>';
                    echo '<input name="productid" type="hidden" id="productid" value="' . $row['product_name'] . '">';
                    echo '<input name="itemtype" type="hidden" id="itemtype" value="' . $row['item_type'] . '">';
                    echo '<input name="vendor" type="hidden" id="vendor" value="' . $row['vendor'] . '">';
                  echo '</td>';
                echo '<td width="103"><img src="' . $row['thumb_name'] . '"></td>';
              echo '</tr>';
            echo '</table></td>';
           echo '<td width="6">&nbsp;</td>';
          echo '</tr>';
          echo '<tr>';
            echo '<td>&nbsp;</td>';
              echo '<td><table width="100%" border="0" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">';
                echo '<tr>';
                 echo '<td height="19"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">View 
              Options</font></td>';
                echo '<td> <table width="175" border="0" cellpadding="0">';
                  echo '<tr>';
                    echo '<td width="90"><a href="stacyclaireboydfonts.pdf" target="_blank">Fonts</a></td>';
                  echo '</tr>';
                  echo '</tr>';
                 echo '</table></td>';
                echo '</tr>';
                echo '<tr>';
                  echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Quantity</font></td>';
                  echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                    echo '<select name="quantity" class="menubox" id="quantity" style="width:150;">';
                      echo '<option selected>Select</option>';
                      echo '<option>25 cards for ' . $row['price1'] . '</option>';
                      echo '<option>50 cards for ' . $row['price2'] . '</option>';
                      echo '<option>75 cards for ' . $row['price3'] . '</option>';
                      echo '<option>100 cards for ' . $row['price4'] . '</option>';
                      echo '<option>125 cards for ' . $row['price5'] . '</option>';
                      echo '<option>150 cards for ' . $row['price6'] . '</option>';
                      echo '<option>175 cards for ' . $row['price7'] . '</option>';
                      echo '<option>200 cards for ' . $row['price8'] . '</option>';
                    echo '</select>';
                    echo '</font></td>';
                  echo'</tr>';
                  echo '<tr>';
                    echo '<td width="29%"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Font*</font></td>';
                    echo '<td width="71%"><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<select name="font" class="menubox">';
                       echo '<option selected>Select</option>';
                        echo '<option>Alex</option>';
                        echo '<option>Anna</option>';
                        echo '<option>Bertram</option>';
                        echo '<option>Boyd</option>';
                        echo '<option>Casual</option>';
                        echo '<option>Childish</option>';
                        echo '<option>Claire</option>';
                        echo '<option>Claire Bold</option>';
                        echo '<option>Clayton Monogram</option>';  
                        echo '<option>Curly Q</option>';
                        echo '<option>Daisy</option>';
                        echo '<option>Elegant</option>';
                        echo '<option>Etched</option>';
                        echo '<option>Fun Times</option>';
                        echo '<option>Fun Times Bold</option>';
                        echo '<option>Gregory Light</option>';
                        echo '<option>Gregory Bold</option>';
                        echo '<option>Gregory Bold Extended</option>';
                        echo '<option>Hebrew</option>';   
                        echo '<option>Hebrew Script</option>';  
                        echo '<option>Hippity Hop</option>';
                        echo '<option>Latte</option>';
                        echo '<option>Michael</option>';
                        echo '<option>Nitro</option>';
                        echo '<option>Rosalyn Monogram</option>';
                        echo '<option>Shadow</option>';
                        echo '<option>Silly</option>';
                        echo '<option>Stacy Light</option>';
                        echo '<option>Stacy Bold</option>';
                        echo '<option>Stylish</option>';
                        echo '<option>Topsy Turvy</option>';
                        echo '<option>Vance</option>';
                      echo '</select>';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td colspan="2"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Please note that Clayton Script, Hebrew and Hebrew Script require a fax proof</font></td>';
                  echo '</tr>';
                    echo '<tr>';
                    echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Layout</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<select name="layout" class="menubox">';
                        echo '<option selected>Select</option>';
                        echo '<option>horizontal</option>';
                        echo '<option>vertical</option>';
                      echo '</select>';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Text 
            Style</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<select name="textstyle" class="menubox">';
                        echo '<option selected>Select</option>';
                        echo '<option>Upper and Lowercase</option>';
                        echo '<option>all lowercase</option>';
                        echo '<option>ALL CAPS</option>';
                      echo '</select>';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Send 
            Proof</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<select name="Proof" class="menubox" id="Proof" style="width:150;">';
                        echo '<option selected>$12 Per Item</option>';
                        echo '<option>Email</option>';
                        echo '<option>Fax</option>';
                        echo '<option>Mail</option>';
                        echo '<option>None</option>';
                      echo '</select>';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Rush 
            Order</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<select name="RushOrder" class="menubox" id="RushOrder" style="width:150;">';
                        echo '<option selected>Select</option>';
                        echo '<option>No</option>';
                        echo '<option>Yes</option>';
                      echo '</select>';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Pre-Shipped Envelopes</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<select name="preship" class="menubox" id="preship" style="width:150;">';
                        echo '<option selected>$12+shipping per order</option>';
                        echo '<option>No</option>';
                        echo '<option>Yes</option>';
                      echo '</select>';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td colspan="2"><table width="278" border="0" cellpadding="1" cellspacing="2" bgcolor="#FFFFFF">';
                      echo '<tr>';
                        echo '<td colspan="2"><font color="#663300" size="3" face="Arial, Helvetica, sans-serif"><strong> 
                  shipping & payment info </strong></font></td>';
                      echo '</tr>';
                      echo '<tr>';
                        echo '<td width="105"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Delivery 
                    <strong><br>';
                        echo '</strong></font></td>';
                        echo '<td width="210"><font size="1" face="Arial, Helvetica, sans-serif">';
                          echo '<select name="Shipping" class="menubox" id="Shipping" style="width:150;">';
                            echo '<option selected>Select</option>';
                            echo '<option>Standard</option>';
                            echo '<option>3-Day</option>';
                            echo '<option>2-day</option>';
                            echo '<option>Next Day</option>';
                          echo '</select>';
                          echo '</font></td>';
                      echo '</tr>';
                      echo '<tr>';
                        echo '<td width="105"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Payment Method<strong><br>';
                        echo '</strong></font></td>';
                        echo '<td width="210"><font size="1" face="Arial, Helvetica, sans-serif">';
                          echo '<select name="PaymentMethod" class="menubox" id="PaymentMethod" style="width:150;">';
                            echo '<option selected>Select</option>';
                            echo '<option>Credit Card</option>';
                            echo '<option>Check</option>';
                          echo '</select>';
                          echo '</font></td>';
                      echo '</tr>';
                      echo '<tr>';
                        echo '<td colspan="2"><font size="1" face="Arial, Helvetica, sans-serif">Special 
                  Notes/Instructions</font></td>';
                      echo '</tr>';
                      echo '<tr>';
                        echo '<td colspan="2"><textarea name="Notes" class="databox5" id="Notes"></textarea></td>';
                      echo '</tr>';
                    echo '</table></td>';
                  echo '</tr>';
                echo '</table></td>';
              echo '<td>&nbsp;</td>';
              echo '<td><table width="90%" border="0" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">';
                echo '<tr>';
                  echo '<td><font color="#663300" size="3" face="Arial, Helvetica, sans-serif"><strong>personalize</strong></font></td>';
                echo '</tr>';
                echo '<tr>';
                  echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Text will be printed exactly as shown. Please capitalize all <br>
              letters that need to be capitalized. </font><br> <font color="#663300" size="1" face="Arial, Helvetica, sans-serif">';
                    echo '<textarea name="personalize" cols="40" rows="5" class="databox4" id="personalize"></textarea>';
                  echo '</font> </td>';
                echo '</tr>';
                echo '<tr>';
                    echo '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Return 
              Address (if applicable):</font><br> <font color="#663300" size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<textarea name="returnaddress" cols="40" rows="5" class="databox4" id="returnaddress"></textarea>';
                      echo '</font> </td>'; 
                  echo '</tr>';
                echo '</table></td>';
              echo '<td>&nbsp;</td>';
            echo '</tr>';
            echo '<tr>';
              echo '<td>&nbsp;</td>';
              echo '<td colspan="3"><font color="#663300">___________________________________________________________________________________________</font></td>';
              echo '<td>&nbsp;</td>';
            echo '</tr>';
            echo '<tr>';
              echo '<td>&nbsp;</td>';
              echo '<td colspan="3"><table width="698" border="0" cellpadding="0">';
                echo '<tr>';
                  echo '<td width="344"><table width="339" border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">';
                    echo '<tr>';
                  echo '<td colspan="2"><font color="#663300" size="3" face="Arial, Helvetica, sans-serif"><strong>billing&nbsp;info 
                  </strong></font><font size="1" face="Arial, Helvetica, sans-serif">( 
                  bold items are required </font>)<font size="3" face="Arial, Helvetica, sans-serif"><strong> 
                  </strong></font></td>';
                echo '</tr>';
                echo '<tr>';
                  echo '<td width="67"><strong><span class="style1"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">name</font></span></strong></td>';
                  echo '<td width="265"><font size="1" face="Arial, Helvetica, sans-serif">';
                    echo '<input name="billname" type="text" class="menubox" id="billname" size="32" maxlength="50">';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="67"><font size="1" face="Arial, Helvetica, sans-serif">company</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billcompany" type="text" class="menubox" id="billcompany" size="32" maxlength="50">';
                      echo '</font></td>';
                   echo '</tr>';
                   echo '<tr>';
                    echo '<td width="67"><strong><span class="style1"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">address<br>
                  &nbsp;line&nbsp;1</font></span></strong></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billaddress1" type="text" class="menubox" id="billaddress1" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="67"><font size="1" face="Arial, Helvetica, sans-serif">address 
                  <br>
                  line 2</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billaddress2" type="text" class="menubox" id="billaddress2" size="32" maxlength="50">';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="67"><strong><span class="style1"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">city, 
                  st, zip</font></span></strong></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billcitystzip" type="text" class="menubox" id="billcitystzip" size="32" maxlength="50">';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="67"><strong><span class="style1"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">phone 
                  1</font></span></strong></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billphone1" type="text" class="menubox" id="billphone1" size="32" maxlength="50">';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="67"><font size="1" face="Arial, Helvetica, sans-serif">phone 
                  2</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billphone2" type="text" class="menubox" id="billphone2" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="67"><strong><span class="style1"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">email</font></span></strong></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="billemail" type="text" class="menubox" id="billemail" size="32" maxlength="50">';
                      echo '</font></td>';
                    echo '</tr>';
                    echo '<tr>';
                      echo '<td width="67"><font size="1" face="Arial, Helvetica, sans-serif">fax</font></td>';
                      echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                        echo '<input name="billfax" type="text" class="menubox" id="billfax" size="32" maxlength="50">';
                        echo '</font></td>';
                    echo '</tr>';
                  echo '</table></td>';
                echo '<td width="348"><table width="348" border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">';
                  echo '<tr>';
                    echo '<td colspan="2"><font color="#663300" size="3" face="Arial, Helvetica, sans-serif"><strong>shipping 
                  info</strong>&nbsp;<font size="1">(if different from billing)</font></font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">name</font></td>';
                    echo '<td width="301"><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipname" type="text" class="menubox" id="shipname" size="32" maxlength="50">';
                    echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">company</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipcompany" type="text" class="menubox" id="shipcompany" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">address 
                  line 1</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipaddress1" type="text" class="menubox" id="shipaddress1" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">address 
                  line 2</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipaddress2" type="text" class="menubox" id="shipaddress2" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">city, 
                  st, zip</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipcitystzip" type="text" class="menubox" id="shipcitystzip" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">phone 
                  1</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipphone1" type="text" class="menubox" id="shipphone1" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">phone 
                  2</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipphone2" type="text" class="menubox" id="shipphone2" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">email</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipemail" type="text" class="menubox" id="shipemail" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                    echo '<td width="40"><font size="1" face="Arial, Helvetica, sans-serif">fax</font></td>';
                    echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
                      echo '<input name="shipfax" type="text" class="menubox" id="shipfax" size="32" maxlength="50">';
                      echo '</font></td>';
                  echo '</tr>';
                  echo '<tr>';
                echo '</table></td>';
              echo '</tr>';
            echo '</table></td>';
          echo '<td>&nbsp;</td>';
        echo '</tr>';
        echo '<tr>';
          echo '<td>&nbsp;</td>';
          echo '<td colspan="3"><div align="center">';
          echo '<input name="Submit" type="image" id="Submit" src="images/buttons/submitorder.gif" alt="submit order" width="150" height="20" border="0">';
          echo '</div></td>';
          echo '<td>&nbsp;</td>';
        echo '</form></tr>';
      echo '</table>';
    }
}

include_once 'footer.html';
?>
I've attempted to put the same Javascript code in my "header.html", nothing happens. I've also tried to break up the php within my order form doc and put the Javascript directly into the order form, or to use echo tags around all the lines of the Javascript code...no luck either way! So I guess at this point, I'm stumped. I know there are ways to validate after the customer has already submitted, and then they hit the back button and fill out the form again. This won't work because it's kind of a long form, and I don't want them to have to re-fill it out every time they make a mistake.

Does anyone know where I can go from here? I would appreciate any suggestions. Thanks in advance!

Jen H.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by snappydesigns on Wed Feb 28, 2007 10:05 am, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Wow.. a mountain of echoes. The Javascript should go in your header.html file. You also have to tell the browser that it needs to call the function at submission time.

I do hope you perform all the validation again in PHP.

Also, <font> tags galore and more importantly, invalid HTML!
snappydesigns
Forum Commoner
Posts: 28
Joined: Tue Feb 13, 2007 11:37 am

Post by snappydesigns »

Thanks, feyd! Sorry I just noticed the dropdown box to put the javascript syntax...will check for that from now on. :oops:, I totally know that my php-style (if you can call it that) is archaic, but it works and it's the only way I know how at this point. As I gain more knowledge in this area, I will try to streamline my process in the future.

I unsuccessfully have tried putting the javascript code within my header.html. I suppose it has something to do with what your suggestion:
You also have to tell the browser that it needs to call the function at submission time.
Can you show me how this might be done? I just assumed what I already had would work since it worked on my html form.

Thanks again!
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

You may wish to look at the Heredoc strings (you can place arrays/variables in curly brackets where you need them).

Code: Select all

echo <<<EOTEXT
This is my echo klsjdhf lkhas lkjfhlkas hdf
which is on multiple lines kasdj hflkajs dfk as
and this is my array value {$myarray['myidex']} aksjdf hlkajs hdlfk alskdj fh
EOTEXT;
To add the function simply add

Code: Select all

<form name="order" method="post" action="orderprocess_donovan_flats.php" onsubmit="return form_check();">
As an aside I hate alerts, especially if the user has one for each error in the form. (They have to OK the alert the resubmit the form for each error).. I prefer to add/remove error text to the form itself next the error inputs. They can then correct all of the form in one go.
Last edited by CoderGoblin on Wed Feb 28, 2007 9:08 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<form ... onsubmit="return form_check()" ... >
form_check() should return true or false to allow the browser to submit or not, respectively.
snappydesigns
Forum Commoner
Posts: 28
Joined: Tue Feb 13, 2007 11:37 am

Post by snappydesigns »

Thanks, feyd and CoderGoblin! It worked. And here I thought it was going to be all complicated, but it just needed that added. Thank you, thank you, thank you!

Did I mention "thank you"?

Thanks again!

Jen H.[/syntax]
Post Reply