Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    server side validation

    I was wondering if anyone could help me i am doing server side validation for my php form and whenever it checks i lose the value when it is redirected back i know for a text box you can just set the value to the php variable but how do i do it for say a select box the user has already selected to make it carry over?

    i have tried this but no success
    Code:
    <select name="pickuphour" class="pole1" id="pickuphour">
                                      <option value="$senderPickuphour"></option>
                                      <option value="01">01</option>
                                      <option value="02">02</option>
                                      <option value="03">03</option>
    this however worked for the text box's

    Code:
    <input name="pickupaddress" value="$senderPickupaddress"  type="text" class="pole1" id="pickupaddress" />

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts
    The trick has to do with how you tell a select input what is selected. You don't set a value anywhere - you instead give the selected option the SELECTED parameter. So you would do something like this:


    <?php
    $selected = array( "", "", "", "" );
    $selected[$senderPickuphour] = " SELECTED";
    ?>
    <select name="pickuphour" class="pole1" id="pickuphour">
    <option></option>
    <option value="1"<?= $selected[1] ?>>01</option>
    <option value="2"<?= $selected[2] ?>>02</option>
    <option value="3"<?= $selected[3] ?>>03</option>
    Make sense? It's a bit confusing because I change from php to html output. The idea is that you output <option value="..." SELECTED>label</option> for the option tag that has been selected.

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im not really following where exactly do i do that after i declared the variable in the php script such as

    $senderPickuphour = $_POST['pickuphour'];

    my webpage im working on is at www.x.com/res_off.cfm if you want to look at the code that page calls a php script which will check the form if it is not filled the page response.php will be displayed and have the exact form displayed with a message at the top saying you must fill in the fields then when all are filled in it will send the email and goto confirmation page.
    The php script which is giving me a headache haha is at www.x.com/phpscript.html

    please help me out with some suggestions thanks man

    I also have javascript validation in place so make sure if your trying it out to disable javascript

    EDIT: Well it was working when i was testing it on http:// _off.cfm

    but now its not working on the website i put it up at weird
    Last edited by cdc515; 10-21-2009 at 06:07 AM.


  •  

    Posting Permissions

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