Contact Form 7 - how to add several number fields dynamically - contact-form-7

I am currently working on a web project where users should be able to have a list of brochures (list comes from custom post type) and enter the amount they would like to order individually for each of them via a simple contact form. My idea was to generate a dynamic list of number fields with the 'wpcf7_form_tag_data_option' hook like in this article:
Dynamicly populate Contact form 7 input fields with current user info when logged in in Wordpress website
So if i am using the select or checkbox field type within contact form 7:
[select anzahlKataloge data:brochures]
or
[checkbox anzahlKataloge data:brochures]
and functions.php:
add_filter('wpcf7_form_tag_data_option', function($n, $options, $args) {
if (in_array('brochures', $options)){
$query = new WP_Query(
array( 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '100', 'post_type' => 'prospekte')
);
while($query->have_posts()) : $query->the_post();
$title = get_the_title();
$brochures[] = $title;
endwhile;
return $brochures;
}
return $n;
}, 10, 3);
It generates the select or checkbox list just fine but i would actually need it to work with the number field type:
[number anzahlKataloge data:brochures]
or with text type:
[text anzahlKataloge data:brochures]
Any help is much appreciated.
Best Regards,
Rafael

Related

flatsome WooCommerce change postcode to dropbox

im new in WordPress i wan to change my WooCommerce check out form postcode to dropdown box.. im using the solution given online but it's not work on my page.. pls help me.
here the code i put inside flatsome child function file.
add_filter( 'woocommerce_default_address_fields' , 'customize_postcode_fields' );
function customize_postcode_fields( $adresses_fields ) {
$adresses_fields['postcode']['type'] = 'select';
$adresses_fields['postcode']['options'] = array(
'' => __('Select your postcode', 'woocommerce'),
'option_1' => 'Choice 1',
'option_2' => 'Choice 2',
'option_3' => 'Choice 3'
);
return $adresses_fields;
}
and the result that i get after apply the code
my display after apply
I have updated my post from earlier which may make it easier for you to interpret and put into your code (I changed it from my last answer, as what I published wont work) - the main difference is putting the array into a variable, to make it easier to change in the future. I have done some research as well and found that the information you provided was the best option for this (so I just cleaned it up a bit). However, if you could also inspect/view-source on your code
function wpe_0987_customize_postcode_fields( $postcode_field ) {
$options = array(
'' => __( 'Select...', 'woocommerce' ),
'choice_1' => 'choice_1',
'choice_2' => 'choice_2',
'choice_3' => 'choice_3',
'choice_4' => 'choice_4'
);
$fields['billing_postcode']['type'] = 'select';
$fields['shipping_postcode']['type'] = 'select';
$fields['billing_postcode']['options'] = $options;
$fields['shipping_postcode']['options'] = $options;
return $fields;
}
For Shipping Field Only!
add_filter( 'woocommerce_shipping_fields' , 'wpe_0987_customize_postcode_fields' );
For Shipping and Billing Fields
add_filter( 'woocommerce_default_address_fields' , 'wpe_0987_customize_postcode_fields' );
Also, when you create custom functions, don't forget to put a custom prefix at the start. At the moment you have 'customize_postcode_fields', you should find a series of letters/numbers or something unique to you to ensure that it doesn't clash with any other theme/plugin - eg: 'random123_customize_postcode_fields' and use that prefix on all custom functions you create in that project.
Update:
Do an 'inspect' or 'view source' on the page, check to see what the 'name' of the postcode form is, and update it with one of the two that I have provided above (shipping_postcode, billing_postcode).

cakephp select dropdown list

i have the following models: Student,Form,FormsStream.
the student model have foreign keys to both models. Student.form_id is a foreignKey to the form table,Student.stream_id is foreign to the FormsStream table. i already have entries for both forms and formsStreams.
to add the student Form and Stream i select both from respective drop-down list. i already created the drop-down list.
my Problem.
previously i was able to save/edit student form and stream but after making those fields foreign keys to be selected i cant save new or edit those fields. i use cakePHP 2.5.4.
however i can do that in SQL.
i cant seem to figure out the problem with the select lists.
my method to get the forms from the database
public function loadStudentForm() {
$this->loadModel('Student'); //load the associated models
$this->loadModel('Form');
$forms = $this->Form->find('list',array('fields' => 'form_name')); //get the forms from the database
$this->set('forms',$forms);
}
method to get streams from database
public function loadStreams() {
$this->loadModel('FormsStream');
$streams = $this->FormsStream->find('list',array('fields' => 'stream_name'));
$this->set('streams',$streams);
}
student add method
public function addStudent() {
if ($this->request->is('post')) {
$this->loadStudentForm();
$this->loadStreams();
$this->Student->create();
if ($this->Student->save($this->request->data)) {
$this->Session->setFlash(__('New student record added to the database.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The student could not be added.Please ensure all fields are correctly entered'));
}
}
}
the extract from add.ctp for selecting student form and stream
echo $this->Form->input('forms',array('label' => 'Form'));
echo $this->Form->input('streams',array('label' => 'Class stream'));
so far printing contents of validateErrors shows this:
array(
'Student' => array(
'form_id' => array(
(int) 0 => 'You must select the form'
),
'stream_id' => array(
(int) 0 => 'You must choose a stream'
)
),
'Form' => array(),
'FormsStream' => array()
)
i've even tried to intercept the request in burpsuite and i can see the form and stream id are passed.just dont get why they are empty in the above array
_method=POST&data%5BStudent%5D%5Badmission_no%5D=1002&data%5BStudent%5D%5Bfirst_name%5D=peter&data%5BStudent%5D%5Bmiddle_name%5D=per&data%5BStudent%5D%5Blast_name%5D=pee&data%5BStudent%5D%5Bgender%5D=Male&data%5BStudent%5D%5Bdate_of_birth%5D%5Bmonth%5D=11&data%5BStudent%5D%5Bdate_of_birth%5D%5Bday%5D=05&data%5BStudent%5D%5Bdate_of_birth%5D%5Byear%5D=2014&data%5BStudent%5D%5Bjoin_date%5D%5Bmonth%5D=11&data%5BStudent%5D%5Bjoin_date%5D%5Bday%5D=05&data%5BStudent%5D%5Bjoin_date%5D%5Byear%5D=2014&data%5BStudent%5D%5Bforms%5D=1&data%5BStudent%5D%5Bsstrong texttreams%5D=1
The input must be form_id and stream_id. Even if you set them with plural form cakephp recognize it in the following form.
echo $this->Form->input('form_id',array('label' => 'Form'));
echo $this->Form->input('stream_id',array('label' => 'Class stream'));

populate id from database in select box option value in zend framework

hi I am new in zend framework Basically I want to populate company name list from the database. Actually I have doen it but i want to also populate its id in option box
example
select
option value='1'> tcs option
select
this is my code
Application_Form_Clientcompanyform extends Zend_Form
$company_list = new Application_Model_Clientcompany;
$showlist = $company_list->companyNameList();
$list=array();
$id=array();
foreach($showlist as $key => $value)
{
$list[]=$value['companyName'];
$id[]=$value['id'];
}
$this->addElement('select', 'companyName', array(
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:103px'),
'multiOptions' => $list,
'decorators'=>Array(
'ViewHelper','Errors'
but Now i want to set the value in option in select box width $id from database
$companyName = new Zend_Form_Element_Select('companyName');
$companyName->setRequired(true);
$companyName->addFilter('StringTrim');
$company_list = new Application_Model_Clientcompany;
$showlist = $company_list->companyNameList();
//add selections to multioption, assumes object...change notation if using array
foreach($showlist as $company) {
$name = ucfirst($company->name);
$companyName->addMultiOption($company->id, $name);
}
$this->addElement($companyName);
I know I changed the syntax style, I just find it easier to keep things straight this way.
Everything else you may need is in http://framework.zend.com/manual/1.12/en/zend.form.html, get used to using the reference and the the api for the framework, they really help.

cake php habtm select does not set selected values

Hello I have several troubles with HABTM and Form.
I am using CakePHP 2.3 and PHP 5.3.3
This is my code situation for the understanding of the scenario: Albums and Singles related with a HABTM relation. Albums cointains many Singles and Singles belongs to many Albums.
Model Album.php ( don't care about raisins: is my personal plugin for managing images )
App::uses('Raisin', 'Raisins.Model');
App::uses('PastryBehavior', 'Raisins.Model/Behavior');
class Album extends AppModel
{
public $name = 'Album';
public $actsAs = array(
'Tags.Taggable',
'Utils.Sluggable' => array(
'label' => 'title'
),
'Raisins.Pastry',
'SrEngine.Indexable',
'SrEngine.HitCounter'
);
public $hasOne = array(
'Image' => array('className' => 'Raisins.Raisin')
);
public $hasAndBelongsToMany = array(
'Single'
);
public $belongsTo = array(
'Users.User'
);
}
Controller AlbumsController.php ( edit part )
$this->request->data = $this->Album->read(null, $id);
$this->set('singles',$this->Album->Single->find('list'));
View
<?php echo $this->Form->input('Single',array('class' => 'span12','label' => 'Singoli' ) ); ?>
In the view I see the select populated from the values coming from the controller singles set, but the selected item, previously saved, is not highlighted.
Consider that in the database the habtm table contains the correct row populated with the data saved.
I read , somewehere in the middle, that some previous version of cake, prior to 2.3, used to have some problem related to habtm form select input.
I am very stuck at this because I have almost tried every known workaround without sorting any positive effect.
Any help, hint would be very appreciated.
Thanks in advance
Rudy

Drupal: set id attribute in multi-step form

I'm building a multi-step form in Drupal 6. For some reason, the id attribute of the form element have an extra "-1" the first time the step 1 form is displayed.
For example, if the form name is "user-registration", the first time I access the step 1 form, the id is "user-registration-1". Then, if I go to step 2, the id is "user-registration". If I go back to step 1, the id remains "user-registration".
I'd like to know if there's a way for me to set the id attribute or to prevent Drupal from adding the extra "-1".
Thanks.
You can set the id yourself.
$form['#attributes'] = array('id' => 'user-registration');
Drupal 6.x has a form API property for both '#id' an '#attribute'. I had the same problem and found that the '#id' property was blank, which accounted for the blank 'id' in the form field. Then I used '#attribute' => array('id' => 'name of id'), which gave me a second 'id' in the form field. Remove the id in the '#attribute' and add another form API property for '#id'.
$form['foo'] = array(
'#type' => 'textfield',
'#title' => t('Foo'),
'#required' => FALSE,
'#id' => 'text-foo',
);
This worked for me:
$form = array( '#id' => 'myformid' );