I want a drupal form which has a dropdown field called appointment time. I would like this field to be prepopulated from an external api call. What approach should I take?
Custom module/Webform?
Thank you!
Drupal has a function called drupal_http_request. I think you can use that inside a hook in a custom module and then populate your field.
I would recommand using hook_form_alter or hook_form_FORM_ID_alter. Inside those hooks you can get to your filter and modify the options of your select. An exemple would be :
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'my_form_id'){
$my_options = array('key' => 'value');
$form['my_field']['#options'] = $my_options;
}
}
So instead of defining the values of the array $my_options you can get the results from your external API et put them in the options of your select field.
Related
I am using smart-table plugin for AngularJS to display a collection information. I have integrated the same with my backend API using the stPipe function which is triggered whenever a search or sort operation is performed. However, I want to place some buttons above the table which act as a filter. When I click on either of these buttons, I want to trigger the stPipe function of smart table and hit the backend API to fetch the filtered results. How can I accomplish this ?
The solution is to put the table state in a controller variable.
Everytime the callServer function is called, it will update this variable. This way, you will be able to refresh the table.
In this code, the callServer would be your stPipe function and your external button would call the refreshGrid() function.
this.tableState = null;
this.callServer = function callServer(tableState) {
ctrl.tableState = tableState;
...
}
this.refreshGrid = function(){
ctrl.callServer(ctrl.tableState);
}
I needed this before and I have posted the solution in this question: Smart table - angularJs - ajax refresh table
I need to implement a custom pagination where one of the fields needs to be populated by a custom PHP method that cannot be implemented using MySQL - ie, I cannot rely on virtualFields.
I tried to use a custom find type, capturing the after event and populating the custom field but the pagination doesn't work with this custom property.
In practical terms, this is what I do to do:
$readers = $this->Paginator->paginate('Reader', array(
'Reader.account_id' => $this->Auth->user('user_id')
));
$readers would have a status property where it's populated using a PHP method. How can I use this dynamic property and the Pagination component at the same time?
Please use these lines
$this->paginate=array('conditions'=> array('Reader.account_id' => $this->Auth->user('user_id')));
$readers=$this->paginate('Reader');
I have a model called User and its $validate has 39 field validations and working fine in UsersController. In another controller I need to use the same code and validate only a single field from controller. Can Someonce please help me with this?
Relevant docs.
Use the fieldList option in the model's validates() method.
$this->ModelName->set($this->data);
if ($this->ModelName->validates(array('fieldList' => array('myField')))) {
// If myField validated successfully...
}
I am using entity registrations to let users register to an event. I have some fields that I want to validate depending on the value of other fields.
So, using hook_form_id_form_alter, i was able to add a second validation function. The second function is where i hoped I can add the code for validating the registration form.
function coastal_custom_form_registration_form_alter($form, &$form_state, $form_id) {
$form['#validate'][] = 'event_registration_form_validate';
}
But whenever I submit the form, the function that is supposed to do the validation never gets called.
//this function never gets called
function event_registration_form_validate(&$form, &$form_state){
drupal_set_message('hi from validation');
form_set_error('you are in form_registration');
}
I have been figuring how to do this for the whole day. Have anyone figured out how this is done? Thanks.
Reading the api documentation on hook_form_alter, I found out that you have to pass by reference $form. So the correct way of writing the function should be:
function coastal_custom_form_registration_form_alter(&$form, &$form_state, $form_id) {
$form['#validate'][] = 'event_registration_form_validate';
}
Take note that there is an ampersand (&) before the $form variable.
I have a list page with a filter form and Im submitting the form using get method. How to pass the querystring parameters along with the pagination links. I have checked this link
CakePHP pagination and the get parameters but this->passedArgs is coming as empty. Im using cakephp2. Whats the best option to solve this ?
This is some code I use in a CakePHP 1.3 project. I believe it should still work on CakePHP 2.0 as well (put this in the view where your filter form is):
// Make sure we pass any set filters to the Paginator helper
$urlParams = $this->params['url'];
unset($urlParams['url']);
$this->Paginator->options(array('url' => array('?' => http_build_query($urlParams))));