Can only get value of $_POST['first_name'] from options.php
-
I created a Menu page in the WordPress Admin that would enable me to add values to the database. These values include things like First Name, Product Title, Product description etc
However I can’t obtain the values through $_POST (except if I add $_POST[‘first_name’] to the options.php page). I can however obtain the value via esc_attr(get_option(‘first_name’)). However I want to be able to do this via the $POST so I can later add these variables to a database
Here is a portion of the code from the relevant pages.
sunset-admin.php
... $picture = esc_attr(get_option('profile_picture')); /*$firstName = esc_attr(get_option('first_name'));*/ $lastName = esc_attr(get_option('last_name')); $fullName = $firstName . ' ' . $lastName; $description = esc_attr(get_option('user_description')); $firstName = $_POST['first_name']; global $wpdb; $table_name = $wpdb->prefix . 'simons_table'; $wpdb->insert( $table_name, array( 'firstname' => $firstName, 'lastname' => 'Hough', 'description' => 'This is the description', ) ); ?> <div class="sunset-sidebar-preview"> <div class="sunset-sidebar"> <div class="image-container"> <div id="profile-picture-preview" class="profile-picture" style="background-image:url(<?php print $picture; ?>);"></div> </div> </div> <h1 class="sunset-username"><?php print $fullName; ?></h1> <h2 class="sunset-description"><?php print $description; ?></h2> <div class="icons-wrapper"> </div> </div> </div> <form method="post" action="options.php" class="sunset-general-form"> <?php settings_fields('sunset-settings-group'); ?> <?php do_settings_sections( 'alecaddd-sunset'); ?> <?php submit_button('Save Changes', 'primary', 'btnSubmit'); ?> </form>
functions-admin.php :
... function sunset_sidebar_name() { $firstName = esc_attr(get_option('first_name')) $firstName = $_POST['first_name']; echo '<input type="text" name="first_name" value="'.$firstName.'" placeholder="First Name"/><input type="text" name="last_name" value="'.$lastName.'" placeholder="Last Name"/>'; }
…
- The topic ‘Can only get value of $_POST['first_name'] from options.php’ is closed to new replies.