I have setup a form where user fill some fields and choose a user type & on submission I have to send him to paypal with the values which he filled up, so that on IPN callback I receive the data from them and do something(this is the procedure I have come to know from reading paypal integration with php), I am stuck at form point because at submission I have another function where I can get the selected value by form_state..
Here is the code --
<?php
//Hook_Menu for paypal callback function.
function user_type_registration_menu(){
$items = array();
$items['paypal/payment/ipn'] = array(
'title' => t('Paypal Payment IPN'),
'description' => t('Paypal Payment IPN'),
'type' => MENU_CALLBACK,
'file' => 'paypal_payment.inc',
'page callback' => 'paypal_payment_paypal_ipn_callback',
'access callback' => TRUE,
);
return $items;
}
//Form alter for registration form.
function user_type_register_form_alter(&$form, &$form_state, $form_id){
switch($form_id) {
case 'user_register_form': // the value we stole from the rendered form
$form['account']['user_type'] = array(
'#type' => 'select',
'#title' => t('Membership Type:'),
'#options' => array(
0 => t('General $50.00/Yr'),
1 => t('Student $40.00/Yr'),
2 => t('Government $60.00/Yr'),
),
'#weight' => -11,
'#description' => t('Select the membership type, which you want to have.'),
);
$form['account']['user_type_submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array('user_type_register_form_submit'),
'#validate' => array('user_type_register_form_alter_validate'),
);
$form['account']['name']['#description'] = t('');
$form['account']['mail']['#description'] = t('');
unset ($form['actions']);// unset the default submit Button
return $form;
break;
}
}
function user_type_register_form_submit($form, &$form_state){
$username = $form_state['values']['name'];
$user_email = $form_state['values']['mail'];
$user_type = $form_state['values']['user_type'];
$password = user_password(8);
switch($user_type){
case '0':
dpm("General");
$membership_price = 50;
$fields = array(
'name' => $username,
'mail' => $user_email,
'pass' => $password,
'status' => 1,
'init' => $user_email,
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',),
);
$account = user_save('', $fields);
$account->password = $fields['password'];
//--Here I have to send if to PAYPAL
dpm("user registered");
break;
case '1':
dpm("Student");
$membership_price = 40;
$fields = array(
'name' => $username,
'mail' => $user_email,
'pass' => $password,
'status' => 1,
'init' => $user_email,
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',),
);
$account = user_save('', $fields);
$account->password = $fields['password'];
//--Here I have to send if to PAYPAL
break;
case '2':
dpm("Government");
$membership_price = 60;
$fields = array(
'name' => $username,
'mail' => $user_email,
'pass' => $password,
'status' => 1,
'init' => $user_email,
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',),
);
$account = user_save('', $fields);
$account->password = $fields['password'];
//--Here I have to send if to PAYPAL
break;
}
}
function user_type_register_form_alter_validate(){
}
I hope somebody can help...