Results 1 to 12 of 12

Thread: how to count no of taxtboxe in php on a wb page

  1. #1
    Join Date
    May 2014

    how to count no of taxtboxe in php on a wb page

    how to count no of taxtboxe in php on a web page

  2. #2
    Join Date
    Dec 2002
    Seattle, WA
    are you pulling the page thru curl/socket request? or outputting the page?

  3. #3
    Join Date
    May 2014
    this is my code:--

    <meta charset="UTF-8">
    <title>Our Local site</title>

    <form action="welcome.php" method="post">
    <input id="t1" name="t1"type="text" placeholder="table name"><br>
    <input id="s1" name="s1" type="text" placeholder="skill">
    <input id="s2"type="text" placeholder="skill">
    <input id="s3"type="text" placeholder="skill">
    <input id="s4"type="text" placeholder="skill">
    <input id="s5"type="text" placeholder="skill">
    <input id="s6"type="text" placeholder="skill">
    <input id="s7"type="text" placeholder="skill">
    <input id="s8"type="text" placeholder="skill">
    <input id="s9"type="text" placeholder="skill">
    <input id="c1"type="text" placeholder="city">
    <input id="c2"type="text" placeholder="city">
    <input id="c3"type="text" placeholder="city">
    <input id="c4"type="text" placeholder="city">
    <input id="c5"type="text" placeholder="city">
    <input id="c6"type="text" placeholder="city"><br>
    <input id="r1"type="text" placeholder="Region in city">
    <input id="r2"type="text" placeholder="Region in city">
    <input id="r3"type="text" placeholder="Region in city">
    <input id="cn1"type="text" placeholder="country">
    <input id="cn2"type="text" placeholder="country">
    <input id="cn3"type="text" placeholder="country">
    <input id="l1"type="text" placeholder="Latitude in degrees">
    <input id="l2"type="text" placeholder="Longitude in degrees">
    <input type="submit">


    upon clicking the submit button i want to count the no of textboxes i have on this page...please suggest method..

  4. #4
    Join Date
    Dec 2002
    Seattle, WA
    You can do
    PHP Code:
    if (isset($_POST)) {
    $_POST holds every form element name/value pair.

  5. #5
    Join Date
    Jul 2013
    Voorheesville NY USA
    Of course, you need a name attribute on all these inputs if you want to find them in the POST array. Id is unnecessary unless you have some JS that needs it.

  6. #6
    @ginerjm has it right. No names, no values server-side. Remember, NAME is for what's sent to the server, ID is what you should target from scripting, CSS or hash. Unless for some reason you want to use nyetscape 4 style form access by name -- which we were supposed to stop doing fifteen years ago -- which is why most developers out there still do it

    Names USUALLY must be unique, but.... you can pass them as arrays.

    <input id="s2" name="skill[]" type="text" placeholder="skill">
    <input id="s3" name="skill[]" type="text" placeholder="skill">
    <input id="s4" name="skill[]" type="text" placeholder="skill">
    <input id="s5" name="skill[]" type="text" placeholder="skill">
    <input id="s6" name="skill[]" type="text" placeholder="skill">
    <input id="s7" name="skill[]" type="text" placeholder="skill">
    <input id="s8" name="skill[]" type="text" placeholder="skill">
    Would let you access those where $_POST['skill'] would be an array containing the values of those inputs.

    Now that said, STOP USING PLACEHOLDER INSTEAD OF LABEL. It is NOT a replacement for LABEL, and that's inaccessible trash no matter how many artsy fartsy types want to piss all over usability with it.


    and the specification:

    ... and I quote:
    The placeholder attribute should not be used as a replacement for a label. For a longer hint or other advisory text, place the text next to the control.
    WHY? and why is the script-tard equivalent also rubbish? FALSE SIMPLICITY.

    So I'm hoping that was just 'for testing', as incomplete inaccessible forms like that are a hefty part of what's wrong with a LOT of websites.

  7. #7
    Join Date
    May 2014
    i get your point and i respec u for giving proof. also i wanna ask can i count inputs using js and then pass the value to server..i mean to php??

  8. #8
    Join Date
    May 2014
    now i have this code

    <!DOCTYPE html>
    To change this license header, choose License Headers in Project Properties.
    To change this template file, choose Tools | Templates
    and open the template in the editor.
    <meta charset="UTF-8">
    <title>Our Local site</title>

    <form action="welcome.php" method="post">
    <input id="t1" name="t1"type="text" placeholder="table name"><br>
    <input id="s1"type="text" name="skill[]"placeholder="skill or item or spec">
    <input id="s2" type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s3" type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s4"type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s5"type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s6"type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s7"type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s8"type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="s9"type="text" name="skill[]" placeholder="skill or item or spec">
    <input id="c1"type="text" name="city[]"placeholder="city">
    <input id="c2"type="text" name="city[]"placeholder="city">
    <input id="c3"type="text" name="city[]" placeholder="city">
    <input id="c4"type="text" name="city[]" placeholder="city">
    <input id="c5"type="text" name="city[]" placeholder="city">
    <input id="c6"type="text" name="city[]"placeholder="city"><br>
    <input id="r1"type="text" name="region[]"placeholder="Region in city">
    <input id="r2"type="text" name="region[]" placeholder="Region in city">
    <input id="r3"type="text" name="region[]" placeholder="Region in city">
    <input id="cn1"type="text" name="country[]" placeholder="country">
    <input id="cn2"type="text" name="country[]" placeholder="country">
    <input id="cn3"type="text" name="country[]" placeholder="country">
    <input id="l1"type="text" name="lat"placeholder="Latitude in degrees">
    <input id="l2"type="text" name="long"placeholder="Longitude in degrees">
    <input type="submit">

    i want to check whether boxes with names city are empty or not..how should i do this???

  9. #9
    Join Date
    Dec 2002
    Seattle, WA
    PHP Code:
    if (isset($_POST)) {
        if (isset(
    $_POST['city'])) {
    $city = array();

            foreach (
    $_POST['city'] as $value) {
                if (!empty(
    $value)) // add only non-empty values...
    $city[] = $value;
    print_r($city); // print the list of cities, excluding empties

  10. #10
    ShrineDesigns has it right, but I'd probably make that a function since with all those different [] you'd probably want to do it on each of them.

    Oh, and @ShrineDesigns, $_POST, $_GET and $_REQUEST always exists and are set, even if empty... so your first IF statement would always be true.

    Also if all you want to do is check if the array is empty, using count would make it simpler.

    function postArrayHasValues($index) {
    	if (!isset($_POST[$index])) return false;
    	return count($_POST[$index]) > 0;
    Which you would call thus:

    echo '
    Has Cities : ', postArrayHasValues('city'), '<br />
    Has Regions : ', postArrayHasValues('region'), '<br />
    Has Countries : ', postArrayHasValues('country'), '<br />';
    You could easily change that to return 0 if it's not set and the count instead of a compare if you need to know how many there are.

    function countPostArray($index) {
    	if (!isset($_POST[$index])) return 0;
    	return count($_POST[$index]);

  11. #11
    Join Date
    Dec 2002
    Seattle, WA
    Quote Originally Posted by deathshadow View Post
    Oh, and @ShrineDesigns, $_POST, $_GET and $_REQUEST always exists and are set, even if empty... so your first IF statement would always be true.
    Hmm... they must've updated that recently. I've always done this for testing for POST
    PHP Code:
    if ($_POST) {
    // ...

  12. #12
    You probably saw someone else doing it and assumed it was right... or misinterpreted the check for an array index existing instead of the element itself. I've seen it enough places being done it's easy enough to mistake it for a valid practice... but the superglobals:


    Always exist, even when empty... and it's been that way since they were introduced in PHP 4.1 and the old $HTTP_POST_VARS was deprecated...

    The deprecated $HTTP_POST_VARS on the other hand, doesn't exist unless there is post data, so maybe that's what you were thinking or what where you learned that from thought still applied. When $_POST was introduced and $HTTP_POST_VARS put on the chopping block, a lot of people just did search/replace in their code, so a lot of things you had to do with the older version are still to be found -- even when unnecessary.

    It's like the people who starting out with mysqli or PDO put their connection in global scope and still try to glue together their queries -- it's how it used to work, they're just not grasping WHY the change was made; much akin to the jacktards who used JavaScript to replicate the TARGET attributes behavior as TARGET is deprecated, without asking "WHY was it deprecated?"

    Basically, the wonderful mismatch you always find between old and new methodologies; particularly if you follow some tutorial instead of going right to the horses' mouth -- the specification and/or official manual...

    ...or simply asking the question "WHY?" WAY too many people these days aren't asking the question.
    Last edited by deathshadow; 05-26-2014 at 07:34 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11128 seconds
  • Memory Usage 2,996KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (12)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (12)postbit
  • (12)postbit_onlinestatus
  • (12)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates