SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    newbie need help with form..

    I am trying to use functions to calculate the cost
    i am not sure how to get my variable from my checkbox
    and i need to calculate if the user is doing the one day conference he pays for one day meal plan if he does the two day conf he gets the two day meal plan and so on..
    I was going to do it like if yes is checked
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    
    <style>
    
    body
    {
    color:black;
    font-size:20px;
    
    }
    h1
    {
    color:orange;
    text-align:center;
    font-size:30px;
    
    }
    p
    {
    
    font-family:"Times New Roman";
    font-size:20px;
    
    }
    </style>
    
    <title>MAJOR PROJECT 1 PHP </title>
    
    </head>
    <body>
    
    <h1>Nerd Roundup </h1>
    
    
    <form method = "POST"
          action = "http://localhost/Assignments php class/calculationprogress.php">
      <fieldset>
        <label>
          Please type your  first name:
        </label>
        <input type = "text"
               name = "fName"
               value = "" /> <br />
                <label>
          Please type your  Last name:
        </label>
        <input type = "text"
               name = "lName"
               value = "" /> <br />
               
        
        Please type your  city:
        <input type = "text"
               name = "city"
               value = "" /> <br />
                 Please type your  State:
        <input type = "text"
               name = "state"
               value = "" /> <br />
        Please type your  Zipcode:
        <input type = "text"
               name = "zipCode"
               value = "" /> <br />
       
    <label for="other">Anything else you want to add?</label>
     <textarea id="other" name="other"></textarea><br />
    	
    
    
    
    
    <fieldset>
      <legend>HOW MANY DAYS</legend>
      <input type = "checkbox"
             name = "chkOne"
             value = "100.OO" /><label>ONE DAY $100.00</label>
      <input type = "checkbox"
             name = "chkTwo"
             value = "175.00" /><label>TWO DAYS $175.00</label>
      <input type = "checkbox"
             name = "chkThree"
             value = "325.00" /><label>THREE DAYS $325.00</label>
      
    <br />
    
    	<fieldset>
      <legend>DO YOU WANT THE MEAL PLAN?</legend>
      <input type = "checkbox"
             name = "mealPlan"
             value = "yes" /><label>YES</label>
            
      <input type = "checkbox"
             name = "mealPlan"
             value = "no" /><label>NO</label>
    <br />
    <br />
    
    <h1>NERD TRACK</h1>
      <select name = "track">
        <option value = "PROGRAMMING TRACK">PROGRAMMING TRACK</option>
        <option value = "NETWORKING TRACK">NETWORKING TRACK</option>
        <option value = "SECURITY TRACK">SECURITY TRACK</option>
        <option value = "WEB TRACK">WEB TRACK</option>
      </select>
     
      <button type = "submit">
        place order
      </button>
    </fieldset>
    </form>
    </body>
    </html>
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <style>
    body
    {

    background-color:#FF00FF;
    }
    h1
    {
    color:orange;
    text-align:center;
    }
    p
    {
    font-family:"Times New Roman";
    font-size:20px;
    }
    h1 {text-align:center;
    }
    </style>
    <title>Assignment3</title>
    </head>
    <body>

    <h1>Personal Information </h1>

    <?php 
    // define the variables
    $confId rand(1,1000);
    $fName $_POST["fName"];
    $lName $_POST ["lName"];
    $city $_POST ["city"];
    $state $_POST ["state"];
    $zipCode $_POST["zipCode"];
    $other $_POST ["other"];
    $chkOne $_POST["chkOne"];
    $chkTwo $_POST["chkTwo"];
    $chkThree $_POST["chkThree"];
    $mealPlan $_POST[""];
    $confTotal 0;
    $no_errors TRUE;
    $total 0;

    checkInput();
    calcPrice();
    printConf();

     
    //checkInput
    function checkInput() {

    if (
    filter_has_var(INPUT_POST"chkOne")){
      print 
    "<p>ONE DAY CONFERENCE</p> \n";
      
    $total += filter_input(INPUT_POST"chkOne");
      
    }

    if (
    filter_has_var(INPUT_POST"chkTwo")){
      print 
    "<p>TWO DAY CONFERENCE</p> \n";
      
    $total += filter_input(INPUT_POST"chkTwo");
      
    }

    if (
    filter_has_var(INPUT_POST"chkThree")){
      print 
    "<p>THREE DAY CONFERENCE</p> \n";
      
    $total += filter_input(INPUT_POST"chkThree");
      
    }
    //end $total 


    if (filter_has_var(INPUT_POST"mealPlan")){
     
    }

    if (
    filter_has_var(INPUT_POST"noFood")){

    }
    // do they want the meal plan

    $track filter_input(INPUT_POST"track");
    // what conference track are they on 


    if(empty($fName))
    {
     
    $no_errors FALSE;

    echo 
    '***FIRST NAME FIELD REQUIRED***** <br />' ;
     
        
        }
        
    //get users first name
       


    if(empty($lName))
    {
    $no_errors FALSE;

     echo 
    '****LAST NAME FIELD REQUIRED***** <br /> ';
     
        
        }
        
    // get users last name
        
    if(empty($city))
    {
    $no_errors FALSE;

     echo 
    '****CITY FIELD REQUIRED***** <br /> ';
      
        }
        
    //get user city
        
    if(empty($state))
    {
    $no_errors FALSE;

     echo 
    '***STATE NAME FIELD REQUIRED***** <br /> ';
        }
    //get user state


    if(empty($zipCode))
    {
    $no_errors FALSE;
     
     echo 
    '****ZIPCODE FIELD REQUIRED***** <br /> ';
     
        }
    //get user zip code



    if(empty($other))
    {
    $no_errors FALSE;
     
     
     
     echo 
    '****TEXT FIELD REQUIRED***** <br /> ';
     
    }
    //get user additional comments

        
    if ($no_errors == FALSE) {

    echo 
    "<br> <a href='major1progress.html'>Go back to form</a>";

        }
    //end function checkInput
        
    //beging function calculateCost
    function calcPrice(){

    global 
    $total
        
    $confTotal =filter_input(INPUT_POST,"confTotal");
        
    $total filter_input (INPUT_POST"total");
        
    $mealPlan filter_input (INPUT_POST"mealPlan");
        
        IF (! 
    filter_has_var (INPUT_POST"mealPlan" )){
        
    $total =="100" $confTotal $total+= 50;
        }
        else if (
    $total=="175"){ $confTotal $total +=75;
        }
        else if (
    $total =="225"){$confTotal $total +=100;
    $no_errors == TRUE;
        }}
    //end function cacluclateCost






    //begin function printConf
    function printConf(){
    global 
    $no_errors;
    $no_errors FALSE;

    if (
    $no_errors == TRUE) {
    print  
    " <p> $fName $lName, <br />you have registered for Nerd Roundup 2013<br />
    your planned track is 
    $track<br />
    <br /> You choose -confDay<br /> with -mPlan<br />
    The total cost is: \$
    $total <br />
        I hear the climate around 
    $zipCode is great this time of year.
        <br />  Please make sure to bring cash, or your credit card to pay for the conference on the first day<br />  
         Your additional comments are as follows: 
          
    $other <br /> </p>
          <p>Your Nerd Roundup confirmation number is  
    $confId .</p> <br /> \n";

     }
         }
     
    //end function printConf



       



    ?>

    </body>
    </html>

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If it's one or two or three days then you should be using radio buttons, not check boxes. For yes or no you only need one check box, not two: checked = yes, not checked = no.

    The data is made available to php in the variable $_POST which is an array. Print it out at the top of your process page to see what you are dealing with
    PHP Code:
    echo "<pre>";
    print_r $_POST;
    echo 
    "</pre>"
    Denny Schlesinger
    web services

  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    the way i explain checkboxes and radio or drown downs is ..

    If you're looking to do Option a AND Option b AND Option c then use Checkboxes if you're doing Option a OR Option b OR Option c use Radio Buttons..

    as for Drop Downs if its ALOT of options then use Dropdown Single or Multi Selection

    For Multiselection you put name='options[]' this will post into an array of options
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  4. #4
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    restarted my project, trying to get the calculations down first.
    Its not doing it right, I need a little help please
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>calculate cose of convention</title>
    <link rel = "stylesheet"
          type = "text/css"
          href = "checkDemo.css" />
    </head>
    <body>
    <h1>how many days</h1>
    
    <h2>calculate cost of convention</h2>
    
    <form action = "http://localhost/Assignments php class/calculate.php"
          method = "post">
    
    <fieldset>
      <legend>How Many Days</legend>
      <input type = "checkbox"
             name = "oneDay"
             value = "100" /><label>oneDay</label>
      <input type = "checkbox"
             name = "twoDays"
             value = "175" /><label>twoDays</label>
      <input type = "checkbox"
             name = "threeDays"
             value = "225" /><label>threeDays</label>
        
    	<fieldset>
     Please Check If you would Like The Meal Plan Added to your total. 
        <input type="checkbox" name="mealPlan" value="Yes" />
    <br />
    <br />
    
    
      <button type = "submit">
        place order
      </button>
    </fieldset>
    </form>
    
    </body>
    </html>
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>calculate please</title>
    </head>

    <body>
    <?php

    $confId 
    rand(1,1000);
    $total =0;
    $no_errors TRUE;

    //meal plan 

    if(!isset($_POST['mealPlan']) && 
       
    $_POST['mealPlan'] == 'Yes'
    {    
    $mealPlan== 'Yes';
         
    $no_errors FALSE;
    echo 
    '****MEAL CHOICE REQUIRED***** <br /> ';}
        
    if (
    filter_has_var(INPUT_POST"oneDay")){
      print 
    "<p>You wanted oneDay</p> \n";
      
    $total += filter_input(INPUT_POST"oneDay");
    }

    if (
    filter_has_var(INPUT_POST"twoDays")){
      print 
    "<p>You wanted  twoDays</p> \n";
      
    $total += filter_input(INPUT_POST"twoDays");
    }

    if (
    filter_has_var(INPUT_POST"threeDays")){
      print 
    "<p>You wanted threeDays</p> \n";
      
    $total += filter_input(INPUT_POST"threeDays");
    }

    else


         if (
    $total == 100 && $mealPlan =='Yes');
     {
    $total += 50;
     } 




     
         if (
    $total == 175  && $mealPlan =='Yes');
     {
         (
    $total += 75);
         }

     

     if (
    $total == 225 && $mealPlan =='Yes');
     {
     (
    $total += 100);
     }}
      


     



    print 
    "<p>The total cost is: \$$total</p> \n
            our Nerd Roundup confirmation number is  
    $confId .</p> <br /> \n";
    ?>
    </body>
    </html>
    <\


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •