Note that there are some explanatory texts on larger screens.

plurals
  1. POCounting $_POST
    primarykey
    data
    text
    <p>I have a big form that contains X amount of posts that has 15 fields per post along with 1 hidden field. </p> <p>Let's assume I have 14 posts. This means my form would send 211 fields (14x15 fields plus 1 hidden field).</p> <p>The user does not have to fill in all fields.</p> <p>I want to count the number of posts that the form sends but I seem to be running into difficulty.</p> <p>Using count($_POST) returns 152. This leads me to believe that count() is ignoring empty fields.</p> <p>As a result, using a formula such as (count($_POST) - 1) / 15 would return the wrong result (10.0666) and is inefficient should the number of fields change in the future.</p> <p>So, does anyone have any ideas as to how to get the proper count of my posts?</p> <p>My form looks like so:</p> <pre><code>&lt;form name="scraped" action="&lt;?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?&gt;" method="post"&gt; &lt;input type="hidden" name="OSscraper_hidden" value="N"&gt; &lt;?php $inpCnt = 0; foreach($articles as $item) { ?&gt; &lt;input type="text" name="title_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="name_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="url_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="img_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="pet_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="color_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="value_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="height_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="weight_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="hair_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="eyes_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="race_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="phone_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="address_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;input type="text" name="zip_&lt;?php echo $inpCnt; ?&gt;"&gt; &lt;?php $inpCnt++; } ?&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload