I am passing a variable with $_POST to another page and on the destination page I want to perform an insert operation and want to use that passed value . The variable “$mygroup” is coming from a forms hidden type field from previous page. I am getting below error on insert operation.
Error Message on insert
Notice: Undefined index: mygroup in D:xamphtdocswordpresswp-contentthemesjupiterfunctions.php on line 455
Form Code (to display my form and here the fetched value from previous page display in the textbox $_POST['mygroup'] … but on insert I get the above error
add_shortcode('insertform','insertform');
function insertform()
{
ob_start();
global $wpdb;
global $form;
global $mygroup;
$mygroup = $_POST['mygroup'];
echo $mygroup;
// fetch all the group names for the drop down
$sql = "SELECT groupname FROM groups WHERE groupname !=''";
$results = $wpdb->get_results($sql) or die(mysql_error());
$form.='<style>form label {margin-bottom:15px;}</style>';
$form.='<form action="" method="post">';
$form.='<label>FirstName: </label><input style="height: 30px; margin-left: 10px;" name="firstname" type="text" placeholder="Enter Your First Name" /><br>';
$form.='<label>Last Name: </label><input style="height: 30px; margin-left: 10px;" name="lastname" type="text" placeholder="Enter Your Last Name" /><br>';
$form.='<label style="margin-right:30px;">Email: </label><input style="height: 30px; margin-left: 10px;" name="email" type="text" placeholder="Enter Your email" /><br>';
$form.='<label>Date of Registration</label><input style="height: 30px; margin-left: 10px;" name="timestamp" type="date" placeholder="Record the date of registeration" /><br>';
$form .= "<label>Groups</label><input style='height: 30px; margin-left: 10px;' name='Group' value='$mygroup' type='text' placeholder='Enter Your email' /><br>";
$form.='<label><input name="usersubmit" type="submit" value="Submit" /></label><br>';
$form.='</form> ';
echo $form;
$string=ob_get_contents();
ob_end_clean();
return $string;
}
Shortcode for insert operation
add_shortcode('insertuser','insertuser');
function insertuser ()
{
if(isset($_POST['usersubmit'])){
ob_start();
global $wpdb;
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email=$_POST['email'];
$timestamp=$_POST['timestamp'];
$group = $_POST['Group'];
if($wpdb->insert(
'members',
array(
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $email,
'timestamp' => $timestamp,
'groupname' => $group
)
) == false) wp_die('New user registration successful'); else echo 'New user registration failed<p />';
$string=ob_get_contents();
ob_end_clean();
return $string;
} // end of if function
} //end of main function