Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to add posts to php


There's an earlier note here about correctly referencing elements in $_POST which is accurate.  $_POST is an associative array indexed by form element NAMES, not IDs.  One way to think of it is like this:  element "id=" is for CSS, while element "name=" is for PHP.  If you are referring to your element ID in the POST array, it won't work.  You must assign a name attribute to your element to reference it correctly in the POST array.  These two attributes can be the same for simplicity, i.e., 
<input type="text" id="txtForm" name="txtForm">...</input>
Comment

how to add posts to php


I know it's a pretty basic thing but I had issues trying to access the $_POST variable on a form submission from my HTML page. It took me ages to work out and I couldn't find the help I needed in google. Hence this post.

Make sure your input items have the NAME attribute. The id attribute is not enough! The name attribute on your input controls is what $_POST uses to index the data and therefore show the results.
Comment

how to add posts to php


<?php

 if (!empty($_POST))
 {
    // Array of post values for each different form on your page.
    $postNameArr = array('F1_Submit', 'F2_Submit', 'F3_Submit');        

    // Find all of the post identifiers within $_POST
    $postIdentifierArr = array();
        
    foreach ($postNameArr as $postName)
    {
        if (array_key_exists($postName, $_POST))
        {
             $postIdentifierArr[] = $postName;
        }
    }

    // Only one form should be submitted at a time so we should have one
    // post identifier.  The die statements here are pretty harsh you may consider
    // a warning rather than this. 
    if (count($postIdentifierArr) != 1)
    {
        count($postIdentifierArr) < 1 or
            die("$_POST contained more than one post identifier: " .
               implode(" ", $postIdentifierArr));

        // We have not died yet so we must have less than one.
        die("$_POST did not contain a known post identifier.");
    }
         
    switch ($postIdentifierArr[0])
    {
    case 'F1_Submit':
       echo "Perform actual code for F1_Submit.";
       break;

    case 'Modify':
       echo "Perform actual code for F2_Submit.";
       break;
           
    case 'Delete':
       echo "Perform actual code for F3_Submit.";
       break;
    }
}
else // $_POST is empty.
{
    echo "Perform code for page without POST data. ";
}
?>

Comment

PREVIOUS NEXT
Code Example
Php :: php preg_replace callback 
Php :: How to create an Invoice with watermark FPDF 
Php :: Wordpress srcset with ACF Image & lazy Load 
Php :: phpmailer valid cert 
Php :: php options list view sidebar (240 x 500), list view results (600 x 180), listing page (450 x 200) 
Php :: adding n days to a DATETIME format value 
Php :: oder system make in laravel 
Php :: get data in two columns in div in loop php 
Php :: dequeue recaptcha wordpress 
Php :: laravel capitalize first letter 
Php :: php get array key by value 
Php :: reset internal pointer mysql query 
Php :: <= in php 
Php :: yii2 multilple andFilterWhere 
Php :: Convert backslash characters PHP 
Php :: php ajax registration form validation 
Php :: verify that a valid login cookie was sent in order to do special things for that logged-in 
Php :: add variables to line in laravel notification 
Php :: yii2 has many where 
Php :: multiple laravel site in one directory 
Php :: phphtml 
Php :: PHP Example - AJAX Poll 
Php :: nl_langinfo — Query language and locale information 
Php :: Replace default WP search and dropdown placeholder 
Php :: remove public from url laravel 7 
Php :: laravel collection chunks 
Php :: default password when you make users in laravel 
Php :: WordPress Plugin Code Definition 
Php :: call node js jquery http php 
Php :: php remove value from array if exists 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =