Want to create User and Content at the same time
| Project: | Drupal |
| Version: | 6.9 |
| Component: | user system |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Hi there, I'm trying to find a way that I can create content (any content, really, but in this specific case, a classified ad using ED_classified).
Basically, I want to (as an admin) create an Ad for someone, getting their information over the phone. I want to create the ad, and somewhere put down their email address. If that email is associated with an account already, it names the author as the User. If the User doesn't exist, then the system will create that Ad, and create the User. The system then emails them to notify them that their account has been created, and to go online to edit the ad, etc.
Is there any way this can be done?
It seems like it should be so easy, and yet I can't do it :(

#1
AFAIK you can't do that automatically but manually shouldn't be a problem.
The process would be:
Would that work for you?
- Arie
#2
That is pretty much exactly what I have to do now.
And it *can* work. It's a bit kludgy though.
What I'd prefer is
The rationale behind making this as quick as possible for the operator is that person will also be doing this live over the radio.
They need to be able to get done and "next caller" as soon as possible, because dead air is bad.
I was really hoping to have this feature implemented by the time the site went live. However, that is the end of the week, so I don't think it'll get done by then.
That's Ok, they can use the workflow you described at first, but the sooner I can get this process automated, the better.
Thanks very much!
JR
#3
Ok, I've done some digging, and the code I'm looking at is in the node.module
from line 792-797
if (user_access('administer nodes')) {// Validate the "authored by" field.
if (!empty($node->name) && !($account = user_load(array('name' => $node->name)))) {
// The use of empty() is mandatory in the context of usernames
// as the empty string denotes the anonymous user. In case we
// are dealing with an anonymous user we set the user ID to 0.
form_set_error('name', t('The username %name does not exist.', array('%name' => $node->name)));
}
Can this code be modified to allow for the creation of users from this interface?
#4
Hey anything is possible but I would suggest adding a contributed to the core and not hacking the core.
A contributed module could use hook_form_alter to add an email field to the form where you create the add.
Then after submission the module checks if the user already exists and then assigns the add to that user (and maybe sends and email)
If the user doesn't exist yet, the module calls the email registration module and creates the user, assigns the node and sends a notification.
Better?
- Arie
BTW You really should post things like this on the developers mailing list. The guys over there do this kind of thing for a living (well a lot of them...)
#5
That sounds like a good idea!
How do I get on this 'mailing list' of which you speak
#6
Et voilà http://drupal.org/mailing-lists
Good luck and please post a little something about your solution here once you figure it out.
- Arie
#7
If I were better at Javascript, I'd have UI suggestions for you, but you want an autocompleting text box that looks up users by whatever. You would add
#autocomplete_path = 'menu_path_that_calls_your_function'to the FormAPI textfield element definition, something like
$items['menu_path_that_calls_your_function'] = array(// menu definition that calls module_userlookup()
);
in your module_menu() function, and (for example)
function module_userlookup($string) {static $results = array();
if (!isset($results[$string])) {
$matches = array();
$sql = ('SELECT DISTINCT i.uid, i.firstname, i.lastname
FROM {user_name_index} i // <--- This is not a native Drupal table, by the way
WHERE (i.lastname LIKE \'%s%%\' OR i.firstname LIKE \'%s%%\') ORDER BY i.lastname');
$references = $limit ? db_query_range($sql, $string, $string, 0, $limit) : db_query($sql, $string, $string);
while ($row = db_fetch_object($references)) {
// Add a class wrapper for a few required CSS overrides.
$matches[$row->lastname .', '. $row->firstname ." [user:$row->uid]"] = '<div class="reference-autocomplete">'. $row->lastname .', '. $row->firstname .'</div>';
}
// Store the results.
$results[$string] = $matches;
}
return drupal_json($results[$string]);
}
The function will return an array, key = The string as is displayed in the text field when selected, value = HTML defining the appearance of the item in the drop down list. The key is what will be returned by the form, so you'll have to embed something in it that you can use to identify the user for processing purposes.
On the processing side, to create a user check out the example from the drupal_execute() documentation (http://api.drupal.org/api/function/drupal_execute/7):
// register a new user$form_state = array();
$form_state['values']['name'] = 'robo-user';
$form_state['values']['mail'] = 'robouser@example.com';
$form_state['values']['pass'] = 'password';
$form_state['values']['op'] = t('Create new account');
drupal_execute('user_register', $form_state);
You might want to add
$form_state['values']['status'] = 1; // status = Active$form_state['values']['notify'] = 1; // sent user notification of the creation of the account
before the drupal_execute() call.
#8
There is an add user action available for the rules module: http://drupal.org/project/rules
Just add a condition that queries if the e-mail is already taken. Then fire the appropriate actions: add user and add as author or just add as author. There is also a token for the generated password, so you can email all relevant account information.
Would be an option I think.
cheers,
criz
#9
@jack_ruby: Did you manage to automate this or are you still using the manual approach?
- Arie
#10
Actually, I did :)
I hired a php guy to do it for me, though.
He modified the code of the ed_classified ads to do it.
What I think the next step would be is seeing if someone wants to make a module that could do this for all Nodes.
I had someone contact me wanting to help, so I may see if he's interested. I gotta get my site working first.
it's www.bandbswapshop.com
Check it out and let me know what you think. It's not *quite* done yet, but it's nearly there :)
JR
#11
Took a quick look and it looks nice already. A few points though:
<p>doing in the title?Once you get close to opening up for business (if you aren't already) you should post your site in http://drupal.org/forum/25
Good luck!
- Arie
#12
Thanks for the advice.
The p tag is there because I wanted the site's motto to be on two lines. I can't figure out how to not show that tag and have it be on two lines in the header
Either the email or the phone number would have to be required. I've struggled with that...
The decision I came to was that we wanted to require email for anonymous users, to reduce spam.
If you are authenticated the email is autopopulated.
If you don't have an email, you probably just need to call it to the radio show :)
The reason for the phone number is so lurkers can call sellers. I should probably make that more clear through instructions
the recent ads on the right is there on all pages. I might drop it from the front... but then I've got blank space on my front page!
I just like really minimalist designs :D
I'll post it up after this weekend. I'll be sitting in on the radio show and entering in people's info, so that should give me a better idea if/what needs to be changed.
thanks 'gain
JR
#13
Automatically closed -- issue fixed for 2 weeks with no activity.