I am integrating Drupal Webform with the CRM Highrise - I'm using the Highrise Drupal module (https://drupal.org/project/highrise) to create some mapping - however I want to extend the module to pass additional form values to the "background" field designated within Highrise, the issue I'm running into is that rather than passing the form value of say "Birthday Party" it's simply returning "array" in Highrise, below is the code I have right now:
//initial variable declaration
$form['#get_eventtype'] = drupal_render($event_type);
//making the call to post to Highrise
case 4:
$background = $form_state['values']['submitted'][$row['cid']];
$background .= $form['#get_eventtype'];
$new_person->setBackground($background);
break;
Have you dumped the value in $background after you retrieve it from the form? It is going to be an array and your value will be in one of the array elements. If you haven't already, I would suggest installing the devel module to help you dig into the form structure.
As a FYI I ended up just using Formstack.com - which gives you the ability to easily map custom fields created in Highrise with the form you create using Formstack. Upon creating a form with Formstack I embedded the JavaScript tag provided and was good to go.
Related
In order to insert an article to Drupal there are thee ways of doing that:
by admin panel - really slow and not feasable if talking about 400 articles
by pure sql - number of tables that have to maintained and calculated (content, core, cat etc.) is quite high and it's not really reliable
by using drupal API - that's something that I was trying to implement but can't find a good documentation on it. What I'm trying to achieve is to use drupal classes and insert content (ie. running a PHP file with (catid,title,introtext....))
Example: what i want to add node in xyz.com/drupal site but my php code should be run in irankmedi.com
Can you please point me into direction where I can find some info on how to manage articles and categories this way?
Thanks in advance
If your request is very specific and you can't find a module that does what you need it shouldn't be too difficult to make a module on your own and import (create drupal) content from your code. Should be something like this:
Create a php file that will do the job.
At start of your script include standard Drupal's bootstrap code so you'll have all Drupal's functionality available in your script
Make code that will read content (from database or feed or something else).
Use Drupal api to insert node programatically:
https://www.drupal.org/node/1388922
Call your script manually or set cron to call it on specific time periods.
First you have to read RSS feed in drupal custom module. Then, following code can create node programatically.
$node = new stdClass();
$node->type = 'blog'; // This type should exist
node_object_prepare($node); // Sets some defaults.
$node->language = LANGUAGE_NONE; // The language of the default
$node->title = "testnode";
$node->body[LANGUAGE_NONE][0]['value'] = "Body";
node_save($node); // function that actually saves node in database
In a multi-step Drupal webform, is it possible to show a value entered in a previous-step page?
For example, the first step page captures a username field as "John", is it possible to show a greeting in next step page, showing Hello John, ... ?
p.s. for anonymous user.
I know this is old, but I needed the same thing so I hope this helps others in search.
I needed values from a previous Webform step for my custom Webform component. The _webform_redner_[component](...) hook doesn't provide the form or form_state, also the previous steps' data (more than previous step that was just submitted) isn't in the $_POST.
To solve this, I manually retrieve the form from Drupal's form caching system using the form_build_id which is in the $_POST variable.
/* ... */
$form_state = array();
// Get the form_state to pass on to our build function.
// Webforms doesn't provide it at this point so we'll need to manually get it using the form's build_id.
$form = form_get_cache($_POST['form_build_id'], $form_state);
/* ... */
You now have the entire form and form_state that also includes previous steps' values.
Have a look at multistep form example here: http://drupal.org/node/717750
The general idea is that in the submit function you save all posted values to $form_state['storage'], which you can later access on the next steps.
Edit:
Have a look at the example with both Prev and Next buttons I have just created: http://zgadzaj.com/basic-drupal-multipart-form-example-with-previous-and-next-buttons
In Drupal 6.20 I'm building a function that creates a multi-page form (my_form_process). On one page the user can select from a list of previously created addresses, or create a new one. If the user wants to create a new one, I use javascript & CSS to hide the selections and unhide the address form (address, city state zip, etc). To make sure the user provides the required data, I have a validate function (my_form_process_validate) that I set the error if the fields are blank. The trouble is that when the pages fails the validation, the my_form_process redraws the form with the validation errors, but defaults back to the "select from a list of previously created addresses", and the "create new" form elements with the errors is still hidden.
How can I tell the my_form_process that builds the form, when the validation has failed show the "create new" div, and hide the "select old" div? I've tried setting a $form['storage'] variable but the my_form_process doesn't seem to see it.
Here is some more info:
I tried adding a $form_state['validation_status'] = 'error' in the validation routine but still found that value not in the $form_state array used in the form function when an error was found.
However, when there was no error, the value was available. (a clue)
So, just for kicks, I removed the "form_set_error" line from the validation routine and now the value is available.
So now, I have to set
$form_state['validation_error'] = '<ol>';
$form_state['validation_status'] = 'error';
$form_state['validation_error'] .= '<li>' . t('address cannot be blank') . '</li>';
$form_state['validation_error'] .= '</ol>';
Then in the form function I can test the $form_state['validation_error'] and if 'error' then use
drupal_set_message($form_state['validation_error'],$form_state['validation_status']);
To display the message and then set the display property of the div's appropriately.
Sure seems like a bug in the "form_set_error" process, but I'm a newbie in Drupal/PHP land so I'm not really sure what I'm doing.
You should be able to pass values through the $form_state variable back and forth between the form function, validation function, and submit handler functions. This might help (if you haven't looked at this already) http://drupal.org/node/144132#multistep
In my multilanguage Drupal 6 website I need to make my CCK field default values translatable, i.e.
Hello - in the English version
Bonjour - in the French one
I cannot find this text with Translation Table, neither are these values in variable table so that I can use multilingual variables.
Do You know how to have different default values in different languages?
When you define the CCK field, you can enter a PHP code snippet to override the default value of the field.
Enter the following there :
return array(0 => array('value' => t('Hello')));
Now access a node add page with this CCK field from a non-English version so that it gets added to translatable strings.
Now you're able to translate it using the "Translate interface" menu (it might take a visit to the "create" page of your cck type first though). It doesn't require any extra modules in fact, just basic D6 (and it probably works in D5 and D7 as well).
This method is a bit of a hack. Im not sure I would deploy this without really considering the consequences. For a simple usecase it MIGHT be ok.
Create a custom module, lets say def_translate. To def_translate.module, add a function
function def_translate_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if($node->type == "sometype"
&& $op == "load"
&& $node->field_some_cck_field_type[0]['value'] == "your default value")
{
$node->field_some_cck_field_type[0]['value'] =
t($node->field_some_cck_field_type[0]['value']);
}
}
Ok - so what is this doing?
When a node is loaded, hook_nodeapi gets called, with $op set to "load". This gives us an opportunity to do manipulate the node before it is rendered. Before we do anything we check
Is this the right type of node?
Is our op = "load"?
Is the value our default value?
What we then do is pass the existing default value through the t() function. This will make the default string available to i18n translation table, and you can then use the normal way of translating strings.
*DISCLAIMER*
I have not tested this myself in production. Im not entirely sure what the effects will be. You probably want to think this through before implementing it, and you probably want to put some features in to look up the default values from the DB incase they are changed in the CCK UI.
Hope this helps - or possibly shakes a hint of a solution to your problem!
How can I build a block in Drupal which is able to show the node ID of the view page the block is currently sitting on?
I'm using views to build a large chunk of my site, but I need to be able to make "intelligent" blocks in PHP mode which will have dynamic content depending on what the view is displaying.
How can I find the $nid which a view is currently displaying?
Here is a more-robust way of getting the node ID:
<?php
// Check that the current URL is for a specific node:
if(arg(0) == 'node' && is_numeric(arg(1))) {
return arg(1); // Return the NID
}
else { // Whatever it is we're looking at, it's not a node
return NULL; // Return an invalid NID
}
?>
This method works even if you have a custom path for your node with the path and/or pathauto modules.
Just for reference, if you don't turn on the path module, the default URLs that Drupal generates are called "system paths" in the documentation. If you do turn on the path module, you are able to set custom paths which are called "aliases" in the documentation.
Since I always have the path module turned on, one thing that confused me at first was whether it was ever possible for the arg function to return part of an alias rather than part of system path.
As it turns out, the arg function will always return a system path because the arg function is based on $_GET['q']... After a bit of research it seems that $_GET['q'] will always return a system path.
If you want to get the path from the actual page request, you need to use $_REQUEST['q']. If the path module is enabled, $_REQUEST['q'] may return either an alias or a system path.
For a solution, especially one that involves a view argument in the midst of a path like department/%/list, see the blog post Node ID as View Argument from SEO-friendly URL Path.
In the end this snippet did the job - it just stripped the clean URL and reported back the very last argument.
<?php
$refer= $_SERVER ['REQUEST_URI'];
$nid = explode("/", $refer);
$nid = $nid[3];
?>
Given the comment reply, the above was probably reduced to this, using the Drupal arg() function to get a part of the request path:
<?php
$nid = arg(3);
?>
You should considder the panels module. It is a very big module and requires some work before you really can tap into it's potential. So take that into considderation.
You can use it to setup a page containing several views/blocks that can be placed in different regions. It uses a concept called context which can be anything related to what you are viewing. You can use that context to determine which node is being viewed and not only change blocks but also layout. It is also a bit more clean since you can move the PHP code away from admin interface.
On a side note, it's also written by the views author.
There are a couple of ways to go about this:
You can make your blocks with Views and pass the nid in through an argument.
You can manually pass in the nid by accessing the $view object using the code below. It's an array at $view->result. Each row in the view is an object in that array, and the nid is in that object for each one. So you could run a foreach on that and get all of the nid of all rows in the view pretty easily.
The first option is a lot easier, so if that suits your needs I would go with that.
New about Drupal 7: The correct way to get the node id is using the function menu_get_object();
Example:
$node = menu_get_object();
$contentType = node_type_get_name($node);
Drupal 8 has another method. Check this out:
arg() is deprecated