www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-03-2009, 08:21 PM
    dvine dvine is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 33
    resolved [RESOLVED] dummy text in input field via php

    Hi Guys,

    Not sure of the best way to explain this, but I will try my best, please allow room for error as I am no php expert. Here is the scenario.

    I have a form which basically autofills input and select fields (which ultimately replaces hidden field labels).

    Now when running through validation, the auto filled text input fields are marked as filled, although the select fields which are also autofilled and have php assigned to the select fields are not marked as filled and validation captures this, which is the desired behaviour. Although I am unsure of how to make the input text field do the same thing.

    A bit of code may possibly be able help identify and explain the situation a little better.

    PHP Code:
    //payment options
    $paymentOptions = array('Pay-as-you-go', '3 Months', '6 Months', '12 Months', '18 Months', '24 Months');

    //validation        
    if (!rv('paymentopt'))
    {
    $errors[] = 'Subscription period field cannot be empty.';
    }
    HTML Code:
    <dt><label for="paymentopt">Subscription Period</label></dt>
    <dd>
    <select class="select" id="paymentopt" name="paymentopt" value="Subscription Period" tabindex="13">
    <option value="">Subscription Period</option>
    [php]<?php
    $paymentopt = rv('paymentopt');
    foreach ($paymentOptions as $paymentOption)
    {
    $selected = '';
    if ($paymentopt == $paymentOption)
    {
    $selected = 'selected=""';
    }
    echo '<option value="'.$paymentOption.'" '.$selected.'>'.$paymentOption.'</option>';
    }
    ?>[/php]
    </select>
    </dd>
    Which above is all good and sweet - as <option value="">Subscription Period</option> is adding the text to the field but it has null value as there is nothing within value.

    The problem begins with regular text fields. I cannot set dummy text with a null value as the previous select option can.

    I need to know how to create an input text value with an initial value that is basically equivilent to null and need the field filled by the user to replace the shown autofilled text.

    I hope I have explained it in an easy enough way to understand.

    Here is some current code that does not exactly do the right thing as it utilises the text that was provided in the value for obvious reasons.

    PHP Code:
    //validate fields
    if (!rv('cname'))
    {
    $errors[] = 'Customer name field cannot be empty.';
    }
    HTML Code:
    <dt><label for="cname">Customer Name</label></dt>
    <dd><input type="text" class="filled" id="cname" name="cname" value="Customer Name" tabindex="1" /></dd>
    The above it not captured by validation because the value is already "Cusomter Name", which basically needs to be null instead, but the field must read Customer Name to identify the field to the user.

    I also tried

    HTML Code:
    <input type="text" class="filled" id="cname" name="cname" value="<?php echo rv('cname'); ?>" tabindex="1" />
    which produced a blank field, although I need the initial value to say Customer Name with a null value.

    The <dt> fields are hidden label fields hence they are not utilised visibly.

    [EDIT]I have a function which autohides the autofilled text when the user clicks in the field so they do not need to delete the preloaded text when filling the field.[/EDIT]

    Hope this is enough information to give you an understanding of what i am trying to achieve. If not let me know.

    But I hope somebody can point me in the right direction.

    Cheers,

    dvine

    Last edited by dvine; 11-03-2009 at 08:29 PM.
    Reply With Quote
      #2  
    Old 11-04-2009, 07:42 AM
    lukaz lukaz is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 62
    Not fully sure I know what you want but if you want a dummie text that does not validate if left, could you not just have:

    PHP Code:
    /* handleing script */

    if($_POST['cname']=='Customer name'){
        
    //your error code here, this will match the string "Customer name" then you can pump out an error if that is what is left in the txt box
    }
    Reply With Quote
      #3  
    Old 11-04-2009, 05:29 PM
    dvine dvine is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 33
    G'Day Lukaz.

    Thank you so much for your reply. You are correct in coming to the conslusion that I do not want the auto text to pass validation.

    Here is what I have done.

    PHP Code:
    //validate fields
            
    if ($_POST['cname']=='Customer name')
            {
                
    $errors[] = 'Customer name field cannot be empty.';
            }
    Although this does not appear to be working correctly, as the auto filled "Customer Name" field still passes validation.

    Are there any other methods, or have I done something incorrectly here?

    Cheers,

    dvine

    Last edited by dvine; 11-04-2009 at 05:33 PM.
    Reply With Quote
      #4  
    Old 11-04-2009, 05:59 PM
    dvine dvine is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 33
    Hi Lukaz,

    Please ignore my previous post, it appears as though it seems to be working now. I am assuming it is case sensitive, hence the initial test did not work. It appears as though this is now working. I will mark as resolved once I have tested the entire form using this method.

    Cheers,

    dvine
    Reply With Quote
      #5  
    Old 11-04-2009, 06:00 PM
    lukaz lukaz is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 62
    Have you mirroed the string exactly? i.e if you value field is Customer Name with cap C and cap N make sure it is the same in the validation script.

    EDIT: glad it works
    Reply With Quote
      #6  
    Old 11-04-2009, 06:01 PM
    dvine dvine is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 33
    On the money mate.

    =)

    Thank you.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:56 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.