I have a need to allow authenticated users to create content in Drupal anonymously. Ideally something like a Suggestion Box. The suggestion should have no fingerprint of who submitted it and ideally it should be submitted but not published until it is reviewed and approved.
Looking at the contact form and other modules, I haven't been able to get a clear direction on how to do this. Ideally I would think that at submission, I'd like to override the Authored By field and set this to anonymous. Is this the right direction or can I create a simple form that would be emailed to someone without ever creating a node?
I would suggest just creating a form using webform module.
If you don't want a node, just create a simple php form that sends a mail() on completion. You will need to enable the PHP filter and then just create a page with the PHP form in the content area.
If you wanted a node, you could create a custom content type called suggestions and then use a custom module to remove the author tag using hook_form_alter.
function uofm_usertasks_form_alter(&$form, &$form_state, $form_id) {
switch($form_id)
{
case 'suggestion_node_form':
$form['authored']['name']['#access'] = FALSE; // not sure if this is the right item in the form or not
break;
}
}
Related
If I need to manage a custom field under wordpress, but not from the admin area. In other words, I need that users modify the content of post custom fields from front end. What is the way to do so?
As instances, please to imagine Stackoverflow.com as a wordpress site. Under this site, the number of upvotes/downvotes and the accept state are my 2 post custom fields. How can I make the front end user modify their values in WP database?
Please If you have another better approach to create votes system and accept system, using wordpress, it will be highly appreciated. But if my approach (using post custom field) is okey, please to guide me find documentation from web or codex to achieve my goal.
Thank you for your usual help.
I would suggest thinking about a couple things:
Each post should show the sum of up-votes and down-votes
Each user should only be able to up or down-vote once (i.e., one user can't vote the same post up a hundred times)
You think you would want to create a function for your theme that allowed users when logged in to alter the metadata of a post. However, this isn't really the case – what you need to do is to allow users to edit an element of their own metadata (see add_user_meta) that is basically just a hash. The metadata could be like array("post-666-vote" => -1, "post-777-vote" => 1) for a downvote of post 666 and upvote of post 777.
So, when loading each post, your vote-tally-renderer would look something like this:
vote = get_post_meta($user_id, "post-" . $post_id . "-vote", true);
if(vote == -1) {
// Render down-arrow voting
} elsif(vote == 1) {
// Render up-arrow voting
} else {
// Render normal arrows
}
Each arrow would probably have to make an AJAX request to update the post's metadata. This is a long tutorial (but it's not super complicated! I promise!) and about 3/4 of the way down it talks about how to use an AJAX request to modify some user's metadata. http://wp.tutsplus.com/tutorials/plugins/a-primer-on-ajax-in-the-wordpress-frontend-actually-doing-it/
The only real major change is that the PHP function that is called by the WP AJAX request would also need a callback function to update the post's metadata, and change the number of votes on the post itself. This way, when the page is reloaded, it will show the proper number of votes.
I am having trouble finding sources of information or example code for a creating a custom module (or any means) to edit the node edit/insert pages.
I am trying to create a Flickr Integration for a node. The Flickr API is not an issue and i can resolve those, it's the Drupal API issues i could use some help or resources of information on.
Here is what i am trying to achive.
User attempts to add or edit a node
User inserts a keyword into a field and presses a button (Get Photos)
Flickr API returns and displays a few images
User clicks on an image and the URL of the image is then added to an input field
on node save or node update a field such as $node->flickrImage[0][value] is updated with the URL selected in 4.
the variable is the available when ever the node is rendered.
I'm not quite sure how to achieve this - I simply need some example code of modifying the node edit/insert pages and I think I can work the rest out.
Please Help!
Thanks,
Shadi
It looks for me, that you can write own CCK field type, so that you can add this to desired content type and process user's input & work with flickr API.
this way, it's easier to manage this field and control it, plus it will be automatically added to node edit/create forms, node loads, etc.
This article might help http://www.lullabot.com/articles/creating-custom-cck-fields
Second way, is to use hook_form_alter
function module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'product_node_form') {
//do smth
}
}
In this case, form_id you want to change, will be {content_type}_node_form.
there you can add your field, and process it on
hook_nodeapi
Here is a link for node edit form alter solution ..
http://drupal.org/node/101092
I need to add a page with a form in my Drupal website. This form should be submitted to another server (there is a php script ready to receive it on such server).
So, I don't need any database update, just a page forwarding the data inserted by users to another domain.
Do you know what's the easiest way to do it ?
thanks
ps. Also, I need to create a drop down menu with a list of countries (and regions for each country) as submenu
I am surprised noone mentioned hook_form_alter and setting #action to an external URL. This will make the form post directly to the other server if you have control of it you can easily redirect back. Lot easier than POSTing from your server. Another way would be to iframe the other script and use the target attribute (set $form['#attributes']['target'] = 'the_iframe' in hook_form_alter). Then you can use JS to 'move' the page after the submit. Upload POSTs to an iframe, you can look into that JS as well. How do you post to an iframe? discusses iframes and forms.
In your form, you can set #action to whatever URL you want. It will post to that url. If you need a GET, instead of a POST, you should also set the #method.
function my_form_builder() {
$form['search'] = array(
//..builds some form elements
);
$form[#action] = 'http://example.com';
return $form;
}
You could create a regular drupal form with the ususal validation stuff and instead of putting the date into the DB send it over to the other site (via post or get or whatever).
To POST to an external URL in your own custom form implementation or using hook_form_alter() to add another submit handler to an existing form, while not showing the request you will want to use drupal_http_request() to send a serverside http request. See this:
http://www.drupaler.co.uk/blog/validating-submitting-forms-other-websites-drupal/428
To accomplish this with the webform module you'll need what you learned above and something like the following:
In D6 /Webform < 3
http://drupal.org/node/543674#comment-2499674
In Drupal 7/Webform 3
http://www.midwesternmac.com/blogs/jeff-geerling/integrate-webform-3x-paypal
have a general idea on how to use hook alter to modify the feel of the registration form .
However the challenge I have is to not only have the user register, but to save some extra data into another table and then redirect user to a new page.
How would I get about doing that? Please help
Again, it'd be easier to plan what you're trying to do and take advantage of common solutions. I suspect what you're after is the Content Profile module.
add a custom function to your form, according to http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#submit-prop for more info
please notice the login page and the login block are different forms, with different form ids for your hook_form_alter.
Just implement hook_user(); when the first parameter is 'register', the registration form is being presented to a user, and the module can change it by adding new form fields (the module needs to return them to Drupal).
How can I create a form that requires anonymous viewers to register in order to view it?
Right now, I've created a content-type (Submit Plan) which is a primary link available to everyone (anonymous + authenticated). I've restricted 'view' user permissions to anonymous users but they can still see the 'Title' input (I don't want that).
I'd like it so that when an anonymous user clicks on 'Adding a Plan' primary link (the Submit Plan content-type), it goes to the page and says:
"You must register for an account" OR
Redirects them to the registration page asking them to register to submit a plan.
I've been searching for a module or maybe some code to use but have come up short on this topic. Any help would be appreciated. Thanks!
If you're going to be redirecting users to the registration page, I'd strongly consider using something like logintoboggan to make the registration > node-creation process smooth. Otherwise, registration is a multi-step process and I'd imagine it being easy for users to lose their way back to the Add a Plan form in the process.
For the "show links or show the form" direction, there are at least two ways of approaching that: 1) create a custom page where you "import" the add_plan form (or show the links). 2) modify the node/add/plan page itself, either through themeing or the fapi (the forms api).
Here's a promising looking post for the first method: http://drupal.org/node/357895.
Here's a place to start with FAPI http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
Here's a post about theming the node form: http://11heavens.com/theming-the-node-form-in-Drupal-6
Without having tried this, I'd probably lean toward method one.
Update: just had another thought: you could also add the plan form to the registration form so they'd fill them out in one shot. I'm not sure of how to do that in general, but the node profile would work if they're only ever going to make one plan, and if not, you can look at how that's put together.
This can be done a few ways.
One, in your menu output, you can change the link to Submit Plan like this:
<?php
global $user;
if ($user->uid == 0) {
print 'Add a Plan';
} else {
print 'Add a Plan'l;
}
?>
The above code looks to see if the user object has a UID. 0 is anonymous, so that will print the link that sends them to register. Otherwise it will take them to the node add form for Submit Plan content type. This also assumes you control your own menu output. You can also override it in a similar manner by using a theme function.
There are a few ways you can do this, so start there and let me know what you think.