[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP how can i have it so so that email form is not sent until the user has finished selecting quantity ..

Posted on 2007-10-04
11
Medium Priority
?
185 Views
Last Modified: 2013-12-13
hi again
I have a PHP email form inputs of name, email, quantity (and price and bulb pulled from database ) .
how do can i have it so so that email is not sent until the user has finished selecting quantity and bulbs.ie the one customer may want to order more than one type of bulb at the one time
Current Form with thanks to  * stefanaichholzer *
<FORM ACTION="Email.php" method=post>
<table border=0>
<tr>
<td width=55>Name
</td>
<td ><input type="text" name="name" size="3" maxlength="3"></td>
</tr>
<td width=75>Email
</td>
<td ><input type="text" name="Email" size="3" maxlength="3"></td>
</tr><tr>
<td width=15>Quantity
</td>
<td ><input type="text" name="qty" size="3" maxlength="3"></td>
</tr>
<tr>
<td>
<p>
      <label for="bname">BULBS:</label></td>
   <td><select multiple name="bname[]" id="bname">
        <option value="">Select Bulb</option>
            <?php
                  while($bname = $imageList->fetch_assoc())
                   {
                         $selected = ($bname['bname'] == $bname) ? 'selected="selected"' : '';
                              echo '<option value="'.($bname['bname']*$bname['price']).'" '.$selected.'>'.$bname['bname']. ' '.$bname['price'].'</option>';
                         }
                  ?>
      </select>  
    </p>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Enter Order"></td>
</tr>
</table>
</form>
0
Comment
Question by:LeighJor
  • 6
  • 5
11 Comments
 
LVL 5

Expert Comment

by:siva_siva
ID: 20012884
Use the below code to check the validation

<script language="JavaScript">
function checkForm()
{
   var name, email, qty;
   with(document.bulbform)
   {
      name            = name;
      email            = Email;
      qty            = qty;
        bname            = ['bname[]'];
   }

   if(trim(name.value) == '')
   {
      alert('Please enter your name');
      name.focus();
      return false;
   }
   else if(trim(email.value) == '')
   {
      alert('Please enter your email');
      email.focus();
      return false;
   }
   else if(!isEmail(trim(email.value)))
   {
      alert('Email address is not valid');
      email.focus();
      return false;
   }
   else if(trim(qty.value) == '')
   {
      alert('Please enter quantity');
      qty.focus();
      return false;
   }
   else if(bname.value == '')
   {
      alert('Please select any bulb');
      bname.focus();
      return false;
   }
   else
   {
      name.value            = trim(name.value);
      email.value            = trim(email.value);
      qty.value                  = trim(qty.value);
        bname.value            = bname.value;
      return true;
   }
}

function trim(str) {
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str) {
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
   return regex.test(str);
}
</script>

<FORM ACTION="Email.php" method=post name="bulbform">
      <table border=0>
            <tr>
                  <td width=55>Name</td>
                  <td><input type="text" name="name" size="3" maxlength="3"></td>
            </tr>
                  <td width=75>Email</td>
                  <td><input type="text" name="Email" size="3" maxlength="3"></td>
            </tr>
            <tr>
                  <td width=15>Quantity</td>
                  <td><input type="text" name="qty" size="3" maxlength="3"></td>
            </tr>
            <tr>
                  <td><p><label for="bname">BULBS:</label></td>
                  <td><select multiple name="bname[]" id="bname"><option value="">Select Bulb</option>
                  <?php
                        while($bname = $imageList->fetch_assoc()) {
                              $selected = ($bname['bname'] == $bname) ? 'selected="selected"' : '';
                              echo '<option value="'.($bname['bname']*$bname['price']).'" '.$selected.'>'.$bname['bname']. ' '.$bname['price'].'</option>';
                        }
                  ?>
                  </select></p></td>
            </tr>
            <tr>
                  <td colspan="2" align="center"><br><input type="submit" value="Enter Order" onClick="return checkForm();"></td>
            </tr>
      </table>
</form>
0
 

Author Comment

by:LeighJor
ID: 20013003
Ok I'm getting the idea but what happens is that each selection of bulb still needs to be submitted and the on return the previous entries are still in form. Some how I need the name and email to remain while the customer is  given the option to choose more
Thanks so far  
0
 
LVL 5

Expert Comment

by:siva_siva
ID: 20013027
In this you will replace your email code in the email part. You name the below code as Email.php.

Email.php
########
<script language="JavaScript">
function checkForm()
{
   var name, email, qty;
   with(document.bulbform)
   {
      name            = name;
      email            = Email;
      qty            = qty;
        bname            = ['bname[]'];
   }

   if(trim(name.value) == '')
   {
      alert('Please enter your name');
      name.focus();
      return false;
   }
   else if(trim(email.value) == '')
   {
      alert('Please enter your email');
      email.focus();
      return false;
   }
   else if(!isEmail(trim(email.value)))
   {
      alert('Email address is not valid');
      email.focus();
      return false;
   }
   else if(trim(qty.value) == '')
   {
      alert('Please enter quantity');
      qty.focus();
      return false;
   }
   else if(bname.value == '')
   {
      alert('Please select any bulb');
      bname.focus();
      return false;
   }
   else
   {
      name.value            = trim(name.value);
      email.value            = trim(email.value);
      qty.value                  = trim(qty.value);
        bname.value            = bname.value;
      return true;
   }
}

function trim(str) {
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str) {
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
   return regex.test(str);
}
</script>

<?php
      $name = '';
      $email = '';
      $qty = '';

      if(isset($_POST['submit'])) {
            $name = $_POST['name'];
            $email = $_POST['Email'];
            $qty = $_POST['qty'];
            // Email Part
      }
?>

<FORM ACTION="Email.php" method="post" name="bulbform">
      <table border=0>
            <tr>
                  <td width=55>Name</td>
                  <td><input type="text" name="name" size="3" maxlength="3" value="<?php echo $name; ?>"></td>
            </tr>
                  <td width=75>Email</td>
                  <td><input type="text" name="Email" size="3" maxlength="3" value="<?php echo $email; ?>"></td>
            </tr>
            <tr>
                  <td width=15>Quantity</td>
                  <td><input type="text" name="qty" size="3" maxlength="3" value="<?php echo $qty; ?>"></td>
            </tr>
            <tr>
                  <td><p><label for="bname">BULBS:</label></td>
                  <td><select multiple name="bname[]" id="bname"><option value="">Select Bulb</option>
                  <?php
                        while($bname = $imageList->fetch_assoc()) {
                              $selected = ($bname['bname'] == $bname) ? 'selected="selected"' : '';
                              echo '<option value="'.($bname['bname']*$bname['price']).'" '.$selected.'>'.$bname['bname']. ' '.$bname['price'].'</option>';
                        }
                  ?>
                  </select></p></td>
            </tr>
            <tr>
                  <td colspan="2" align="center"><br><input type="submit" name="submit" value="Enter Order" onClick="return checkForm();"></td>
            </tr>
      </table>
</form>
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:LeighJor
ID: 20018158
Sorry Siva Siva
I cant get it to work
I think i need 2 buttons one to send email and one to allow multiple selections until email button is sent
0
 
LVL 5

Expert Comment

by:siva_siva
ID: 20020353
I can't understand your requirement...

Actually why you need 2 buttons?
1. One button is to submit email.
2. You select multiple selection before when you click the submit button.. Why you need that second button?
0
 

Author Comment

by:LeighJor
ID: 20020672
Sorry Siva Siva .I am new to this
I want the form to look like this
  ***from database***          *Entered into Box*    
                 v
BULB NAME     PRICE                 Qty                           Total
apple                 20                      7                                Qty*Pice
pear                  40                        9                                    "

I think i can get the lists  but if qty is from input box how do iI reference in the Total column and
how do I get the email to look this
Thanks for your patience
Leigh Jor
0
 
LVL 5

Expert Comment

by:siva_siva
ID: 20020789
For this you have to replace the multiple select list box to the following code, then only customer will give different type of quantity to different bulbs

<tr>
      <td>Bulb Name</td>
      <td>Price</td>
      <td>Quantity</td>
</tr>
<tr>
      <?php
            $i = 0
            while($bname = $imageList->fetch_assoc()) {
      ?>
            <td><input type="text" name="bname_$i" value="<? echo $bname['bname']; ?>" disabled></td>
            <td><input type="text" name="price_$i" value="<? echo $bname['price']; ?>" disabled></td>
            <td><input type="text" name="qty_$i" value="<? echo $qty; ?>"></td>
      <?php
            $i++;
            }
      ?>
</tr>
0
 

Author Comment

by:LeighJor
ID: 20027036
Hi Siva Siva
I cant get the total column to work.
Can i call on the value of any input form before it is submitted? Thanks again

<td>Total</td>
</tr>
<tr>
     <?php
         $i = 0;
         while($bname = $imageList->fetch_assoc()) {
     ?>
<tr>
     <td><input name="bname_$i" type="text" value="<? echo $bname['bname']; ?>" size="50" disabled></td>
       <td><input name="price_$i" type="text" value="<? echo $bname['price']; ?>" size="10" disabled></td>
            <td><input name="qty_$i" type="text" size="10" value="<? echo $qty; ?>" ></td>
                <?php
               $p='bname_$i';
                               $q='$qty';
               $total= $q*$p ;
                 ?>      
         <td><input type="text" name="total" value="<? echo $total; ?>"></td>
 </tr>
    <?php
            $i++;
             }
      ?>
</tr>
0
 
LVL 5

Accepted Solution

by:
siva_siva earned 2000 total points
ID: 20027049
In this you will write a javascript function to find total value.

<input name="qty_$i" type="text" size="10" value="<? echo $qty; ? onchange="find_total();">
0
 

Author Comment

by:LeighJor
ID: 20027061
Thanks Siva Siva
0
 
LVL 5

Expert Comment

by:siva_siva
ID: 20027079
Most welcome LeighJor
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

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