jeudi 1 janvier 2015

Gravity Forms: get and set field types


Vote count:

0




I am trying to create a function for Gravity Forms that will allow me to set the field name as a variable for use across all of my forms. For instance, I want to use $firstName rather than $entry['1.3']. I have multiple forms where the entry IDs may not always match each other, and I'd rather have a way to deploy these functions more globally rather than on a form-by-form basis.


This is part of the function I have in place (it is part of a larger class called MBFormData, I'm not including all of the code here to save space):



function loadForm(&$form) {
foreach ($form['fields'] as &$field) {
$id = $field['id'];
switch(GFFormsModel::get_input_type($field)){
case 'name':
// only pick up the first name field (assume later ones are additional info)
if (empty($this->firstName) && empty($this->lastName)) {
$this->namePrefix = rgpost("input_{$id}_2");
$this->firstName = rgpost("input_{$id}_3");
$this->lastName = rgpost("input_{$id}_6");
}
break;
case 'email':
// only pick up the first email address field (assume later ones are additional info)
if (empty($this->email))
$this->email = rgpost("input_{$id}");
break;
case 'creditcard':
$this->isCcHiddenFlag = GFFormsModel::is_field_hidden($form, $field, RGForms::post('gform_field_values'));
$this->ccField =& $field;
$this->ccName = rgpost("input_{$id}_5");
$this->ccNumber = self::cleanCcNumber(rgpost("input_{$id}_1"));
$ccExp = rgpost("input_{$id}_2");
if (is_array($ccExp))
list($this->ccExpMonth, $this->ccExpYear) = $ccExp;
$this->ccCVN = rgpost("input_{$id}_3");
break;
default:
// check for product field
if (in_array($field['type'], array('option', 'donation', 'product', 'calculation'))) {
$this->amount += self::getProductPrice($form, $field);
$this->hasPurchaseFieldsFlag = true;
}
break;
}
}


I am then calling that function in each of my form-specific functions and trying to add data into an array using this function, like so:



$formData = new MBFormData($data['form']);

array(
'CreditCardNumber'=>$formData->ccNumber,
'FirstName'=>$formData->firstName,
'ExpYear'=>$formData->ccExpYear,
'ExpMonth'=>$formData->ccExpMonth,
)


However, when I print_r the request, the fields are empty. Note that the code works perfectly when I use $entry['x'] per form for the variables in the array.


Any ideas what I am doing wrong? Basically, I need a function in place so that I can use something like $firstName and $ccNumber across all of these forms, rather than implementing functions per form using $entry['2'], etc. These forms are used to submit data and take payments via a SOAP API.


Any advice is appreciated.



asked 1 min ago

Greg

81






Gravity Forms: get and set field types

Aucun commentaire:

Enregistrer un commentaire