/    Sign up×
Community /Pin to ProfileBookmark

Input tag validation

Hey all,

does anyone know a bit of php script that formats every <input type=”text”> tag inside a form so that the first letter of each word becomes a capital letter?

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 31.2006 — You mean, as you type? PHP can't do that

but you can use the [url=http://php.net/ucwords]ucwords()[/url] function when you process the data.

why would you want to do that anyway?
Copy linkTweet thisAlerts:
@peteybauthorMar 31.2006 — Not as a user types but when they submit the form.

It is necessary as the data they input will be put into a form that will make up the documentation for their purchase.

the boss is up on aesthetics!!!
Copy linkTweet thisAlerts:
@bokehMar 31.2006 — Just a quick question: Are you trying to capitalize the first letter of the string or the first letter of each word in the string?
Copy linkTweet thisAlerts:
@peteybauthorMar 31.2006 — the latter, the first letter of each word in the string
Copy linkTweet thisAlerts:
@bokehMar 31.2006 — [code=php]<?php

#The following array contains the fieldnames of the inputs you want to capitalize
$to_capitalize = array('fieldname1', 'fieldname2', 'fieldname3', 'fieldname4');

foreach($to_capitalize as $fieldname)
{
$_POST[$fieldname] = ucwords($_POST[$fieldname]);
}

?>[/code]
Copy linkTweet thisAlerts:
@peteybauthorMar 31.2006 — isnt it easy when you know how!!!

cool, thanks.

much appeciated
Copy linkTweet thisAlerts:
@peteybauthorMar 31.2006 — whilst we got the thread running, how would i alter this code to make only the first letter of the string capital?
Copy linkTweet thisAlerts:
@bokehMar 31.2006 — whilst we got the thread running, how would i alter this code to make only the first letter of the string capital?[/QUOTE]ucfirst()
Copy linkTweet thisAlerts:
@peteybauthorMar 31.2006 — thank you....theres a slight problem.

i think theres something wrong with my script. if i explain the symptoms hopefully someone can help.

my script is split into two sections, top and bottom. the top is made up of php validation for the html forms, which are at the bottom.

when the user fills out their details and presses either submit button the form actions ['PHP_SELF'].

my code is structed as follows:

1) form submitted

2) mysql connect

3) $errors = array();

4) validation - eg is_numeric, empty etc

(this is for each field and if any are wrong the $errors[] is designated)

5) if the errors array is empty they either move forward/backward depending on which button pushed

6) if errors array not empty stay on page and show errors

7) mysql close


Now onto the prob. If the user enters data and submits the form with errors in the array the page is reloaded with the errors displayed but the ucwords is not applied, then if the user resubmits the form with errors again the page is reloaded but the ucwords is applied.

Why would this happen???
Copy linkTweet thisAlerts:
@bokehMar 31.2006 — Can I see the script?
Copy linkTweet thisAlerts:
@peteybauthorApr 03.2006 — heres the code.
Copy linkTweet thisAlerts:
@bokehApr 03.2006 — That script doesn't contain [I]ucwords()[/I] anywhere. Where are you applying it?
Copy linkTweet thisAlerts:
@peteybauthorApr 03.2006 — sorry, its too big for one upload so have split into 2
Copy linkTweet thisAlerts:
@peteybauthorApr 04.2006 — hows it goin with the code bokeh?

any recommendations? (other than starting again!!!!)
Copy linkTweet thisAlerts:
@tgrk35Jun 13.2006 — Why not just use CSS?

For each input tag (or for all of them at once), use the following:

text-transform: capitalize;

OR

text-transform: uppercase;

That'll get it going right at the start without processing the form first.

Will ?
Copy linkTweet thisAlerts:
@bokehJun 13.2006 — Why not just use CSS?[/QUOTE]Because:[list]
  • [*]this is the PHP forum

  • [*]it is unnecessary

  • [*]server side formatting is preferable

  • [*]server side formatting saves bandwidth

  • [*]it's nice to do it properly rather than have one hash covering for another one

  • [/list]


    Also did you notice that this thread was several months old?
    Copy linkTweet thisAlerts:
    @tgrk35Jun 13.2006 — Uh...ok...

    Thanks, ass...You've really helped everyone out.
    ×

    Success!

    Help @peteyb spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...