SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tick box for autocompletion or other method without JavaScript

    Hi there,

    I have a form (below) whereby a customer enters their delivery and billing address. If they enter a different delivery and billing address then it works fine...it stores $first, $surname, $telephone, $email, $deliveryaddress, $deliverypostcode, $billingaddress, $billingcode, etc.

    But if they are the same, I do not want to ask customers to enter their address twice. I have added a tick box in the form below. How do I code it to say 'if the user ticks the box:

    $deliveryaddress = $billingaddress
    $deliverypostcode = $billingcode

    ???

    I did think about an autocompletion but I DO NOT WANT TO USER ANY JAVASCRIPT - some users disable or do not install it.

    PHP Code:
    <p>Delivery address:</p>
        <
    p>
        <
    label for="address1">Address 1:</label>
        <
    input type="text" name="address1" id="address1" />
        <
    br />
        <
    label for="address2">Address 2:</label>
        <
    input type="text" name="address2" id="address2" />
        <
    br />
        <
    label for="address3">Address  3:</label>
        <
    input type="text" name="address3" id="address3" />
        <
    br />
        <
    label for="address4">Address 4:</label>
        <
    input type="text" name="address4" id="address4" />
        <
    br />
        <
    label for="city">City:</label>
        <
    input type="text" name="City" id="city" />
        <
    br />
        <
    label for="county">County:</label>
        <
    input type="text" name="county" id="county" />
        <
    br />
        <
    label class="postcode" for="postcode">Post code:</label>
        <
    input type="text" name="postcode" id="postcode" />
        <
    br />
        
        </
    p>
        <
    p>Tick this box if the billing address is the same as the delivery address.
      <
    input name="billingsame" type="checkbox" value="yes">                     
          
        </
    p>
    <
    p>Billing address:</p>
        <
    label for="billaddress1">Billing Address 1:</label>
        <
    input type="text" name="billaddress1" id="billaddress1" />
        <
    br />
        <
    label for="billaddress2">Billing Address 2:</label>
        <
    input type="text" name="billaddress2" id="billaddress2" />
        <
    br />
        <
    label for="billaddress3">Billing Address  3:</label>
        <
    input type="text" name="billaddress3" id="billaddress3" />
        <
    br />
        <
    label for="billaddress4">Billing Address 4:</label>
        <
    input type="text" name="billaddress4" id="billaddress4" />
        <
    br />
        <
    label for="billcity">City:</label>
        <
    input type="text" name="billCity" id="billcity" />
        <
    br />
        <
    label for="billcounty">County:</label>
        <
    input type="text" name="billcounty" id="billcounty" />
        <
    br />
        <
    label class="billpostcode" for="postcode">Post code:</label>
        <
    input type="text" name="billpostcode" id="billpostcode" />
        <
    br /> 
    Hope you can help,

    Matt.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Already answered here.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    In your form handler, prior to storing in the database but before any validation/security you are doing ...
    PHP Code:

    if( isset($_POST['billingsame']) ){

    // reassign delivery address to billing address
    $_POST['billaddress1'] = $_POST['address1'] ;
    ... 
    etc


    }

    // from hereon, as normal ... 
    If you want to see for yourself the difference between the checkbox being set or not, just add

    var_dump($_POST);

    to the top of your form handler.

    Edit:

    Oh, right, already answered ...


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
  •