don’t really NEED the entire $_POST stack?
-
First sorry for the length.
So I am working on my first plugin and trying to submit it to be published. So in a nutshell, the plugin utilizes the Entity Attribute Value data model, and allows the user to create tables and fields and to store data. Because of the dynamic nature the forms used to enter data is created dynamically. So when the use pushes the submit button, the code at runtime doesn’t know the fields being submitted. So I have code like this:
if (isset($_POST['submit']) ){ $keyarray = array_keys($_POST); $valarray = array_values($_POST); $insert_tbl = sanitize_text_field($_POST['tablename']);
The issue/problem that I am having is that in submitting the plugin, the response is that I “don’t really NEED the entire $_POST stack. You don’t. You should be using a proper key for your code (like $_POST[‘YOUR_PLUGIN_NAME’] and then you can process everything in that. It will prevent you from accidentally leaking data, make your plugin faster, and be over all more secure.”
Because I don’t know the values (because everything is driven by the database) I need to look at all the values to find the field names and the value of the field. So how do I explain this?
Below is the code where I use both $keyarry and $valarray. I use keyarray to get the fieldname (that is store in the database, and valarray for that value as shown in the code below.
$sz = sizeof($_POST); // find new row number $maxid = "select max(entity_id) as maxid from eav_entity where entity = " . $v_entity; $result_tbl1 =$wpdb->get_row($maxid); $v_entity_id = sanitize_text_field($result_tbl1->maxid) + 1; for ($i=0; $i < $sz; $i++) { if ( ((sanitize_text_field($keyarray[$i]) == 'tablename') || (sanitize_text_field($keyarray[$i]) == 'submit')) == false) { $fieldid = "select entity_attrib from eav_attrib where entity_name = '" . sanitize_text_field($keyarray[$i]) . "'"; $result_fld = $wpdb->get_row($fieldid); $v_entity_attrib = sanitize_text_field($result_fld->entity_attrib); $prep = $wpdb->prepare ( "INSERT INTO eav_entity (entity, entity_id, entity_attrib, val_char) values (%s, %s, %s, %s)" , $v_entity . '' , $v_entity_id . '' , $v_entity_attrib . '' , sanitize_text_field($valarray[$i]) . '' ); $return = $wpdb->query($prep ); if ($return != 1) { echo "<P>Insert into eav_entity failed: " . ' - wpdb->last_error : ' . $wpdb->last_error; } $wpdb->flush(); } }
thanks for your help and if anyone is interested let me know I would be willing to show you more.
thanks
-brad
- The topic ‘don’t really NEED the entire $_POST stack?’ is closed to new replies.