Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could write a custom module which uses the form_alter hook. Then for your CCK form, you can check to see if the user is logged in or not and if not, add a username/password fields to the form for the user to fill out. then add a custom validation function to the form, so that when the form is submitted your validation function attempts to programatically login the user. If login fails then display a form error, else set the global user to the logged in user. so by the time the form hits its submit function the user should be logged in.</p> <p>So something like this for your custom module:</p> <pre><code>&lt;?php function mymodule_form_alter(&amp;$form,&amp;$form_state,$form_id){ global $user; //only for the form we are looking for, and if the user is anonymous if (($form_id == 'my_form_id') &amp;&amp; ($user-&gt;uid==0)){ $form['login'] = array( '#type' =&gt; 'fieldset', '#title' =&gt; 'Login', ); $form['login']['username'] = array( '#type' =&gt; 'textfield', '#title' =&gt; 'Username', '#required' =&gt; true, ); $form['login']['password'] = array( '#type' =&gt; 'password', '#title' =&gt; 'Password', '#required' =&gt; true, ); $form['#validate'][] = 'mymodule_my_form_validate'; } } function mymodule_my_form_validate(&amp;$form,&amp;$form_state){ global $user; //stop from re-login if there were other validation errors if ($user-&gt;uid == 0){ $username = $form_state['values']['username']; $password = $form_state['values']['password']; //authenticate the user (attempt to login) if ($uid = user_authenticate($username,$password)){ $user = user_load($uid); //finalize login user_login_finalize(array('name'=&gt;$username,'pass'=&gt;$password)); }else{ form_set_error('username','Invalid username or password'); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload