Array into variables - Stuck for a few hours now
Posted: Sun Oct 24, 2010 11:45 am
Hey been awhile since I posted here, I am using a contact form script on a wordpress site but I have changed it to submit data to the database instead of mail.
The way the scripts handles the posted data is confusing but this is how it does it originall before editing:
This creates a record per field of the form, so if i have a 20 field form there will be 20 database records. I cant use this I need 1 record per form submit. This is what I have tried to do but it is clearly wrong:
the names of the contact fields are yourname/youremail/yourmessage so i tried using extract to sperate each name and the value to a variable. That is what I understood from google but im now lost as every record is now blank so the variables clearly have no values.
Please help
The way the scripts handles the posted data is confusing but this is how it does it originall before editing:
Code: Select all
public function saveFormData($cf7) {
global $wpdb;
$time = $_SERVER['REQUEST_TIME'] ? $_SERVER['REQUEST_TIME'] : time();
$ip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$tableName = $this->prefixTableName('SUBMITS');
$parametrizedQuery = "INSERT INTO `$tableName` (`submit_time`, `form_name`, `field_name`, `field_value`) VALUES (%s, %s, %s, %s)";
$title = $this->stripSlashes($cf7->title);
foreach ($cf7->posted_data as $name => $value) {
$value = is_array($value) ? implode($value, ", ") : $value;
$wpdb->query($wpdb->prepare($parametrizedQuery,
$time,
$title,
$this->stripSlashes($name),
$this->stripSlashes($value)));
}
Code: Select all
foreach ($cf7->posted_data as $name => $value) {
extract($value);
}
$parametrizedQuery = mysql_query("INSERT INTO `$tableName` (`submit_time`, `form_name`, `field_name`, `field_value`) VALUES ('$time', '$yourname', '$youremail', '$yourmessage')");
Please help