Graviy Forms - gform_user_registration_update_user_id - gravity-forms-plugin

This filter can be used to override which user is used to populate the form and updated when the form is submitted.
Case:
Using gravity forms to update another user, update user base on Email field in another form, not currently logged.
gform_user_registration_update_user_id
We create form (form id 12) with 2 fields, email (field id 1) and userid (field id 2), we use email (field id 1) to find user ID and save it in (field id 2) to pass to form (form id 8) to override user ID in it.
add to theme functions.php
add_filter( 'gform_pre_submission_12', function( $form ) {
$email = rgpost( 'input_1' );
$user = get_user_by( 'email', $email );
$userId = $user->ID;
$_POST['input_2'] = $userId;
} );
We also set Regitration Gravity Forms add-on in (form id 8) to Update mode.
So now we have user ID and need to pass it to (form id 8), so we go to (form id 12) Settings - Confirmation and choose Redirect and place in Redirect URL path to form (form id 8), Redirect Query String checked and placed userid={userid:2}
So after (form id 12) submited we redirect to (form id 8) with userid=ID in url string, like:
http://example.com/form8&userid=3
Now we need to recieve userid on form id 8, we get it with rgget from url path since it already was added to it from redirect from form id 12
add to theme functions.php
add_filter( 'gform_user_registration_update_user_id_8', 'override_user_id', 10, 4 );
function override_user_id( $user_id, $entry, $form, $feed ) {
$user_id = rgget( 'userid' );
return $user_id;
}
Also it changes user ID to update right profile on submit, with override user ID.
Thanks to gravity support i know how and what ^) best support ever. Hope it helps other people.

Related

To stop form submit on every refresh after one submit in codeigniter

After form submission , any number of refresh is storing the data that many times in the db.
ie. !empty($_POST) is always true after on submission.
How can I stop the submission without redirecting the page/url. As I want to stay in the same page.
I am using form_open() and form_submit() i codeigniter.
in view
<?php echo form_open("",array('method' => 'POST'));?>
/* form fields */
'Send', 'value' => 'Send Notifications',"name"=>"send_notification")); ?>
in controller
`if (!empty($_POST['send_notification'])) {
/* validation rules & data*/
if ($this->form_validation->run() == TRUE){
$this->model->insert($data);
}
}`
How can I stop the duplicate record insertion, I have tried , unset($_POST) , isset() , if($this->input->post()) , nothing seems to work.
Just do a redirect(); to the same age after the insert function.
This worked for me. It may help someone
Controller file :
public function success()
{
$_SESSION['txnid'] = $this->input->post('txnid');
$this->bind->set_order();
$this->load->view('success');
}
Model file :
public function set_order()
{
$txnid = $_SESSION['txnid'];
$qry = $this->db->query("SELECT * from orders where transaction_id = '$txnid'");
$result = $qry->result_array();
if($qry->num_rows() == 0 )
{
//add to database here
}
else
{
// do nothing
}
}
I am adding txnid to database on submit. So if it tries to resubmit, it checks if txnid already exist or not.

Script access to custom address field through addressbook

I am having trouble setting a text value in a custom field I added to the address form.
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
console.log("selected line " + lnSeq);
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
console.log('agency' + ',' + agency_campus);
}
nlapiCommitLineItem('addressbook');
console.log('after commit: '
+ nlapiGetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd'));
}
}
This script(applied to the Customer Form under the custom code tab) will not set custrecord_bsi_agy_div_bur_sd with the text value from custentity_bsi_agycampus (a custom field in the customer form). However, if I change custrecord_bsi_agy_div_bur_sd to addr1 (a field that is a default in the address form), it works just like I'd like.
This leads me to wonder whether or not I can access my custom field in the address form through 'addressbook' like you can for all of the other address fields. Does anyone know the answer to that question or have an idea of how I can troubleshoot this issue?
I believe you need to work with addresses as subrecords. Play around with something patterned after this:
// {nlobjSubrecord} Get one of the addresses off the sublist
var subrecord = {};
nlapiSelectLineItem('addressbook', 1);
subrecord = nlapiEditCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
// Set the data on the subrecord
subrecord.setFieldValue('attention', 'Some Guy');
subrecord.setFieldValue('addr1', '1234 5th St');
subrecord.setFieldValue('addr2', 'Apt 234');
subrecord.setFieldValue('addrphone', '5558675309');
subrecord.setFieldValue('city', 'Scottsdale');
subrecord.setFieldValue('state', 'AZ');
subrecord.setFieldValue('country', 'US');
subrecord.setFieldValue('zip', '85260');
// Commit the subrecord to its parent before submitting the parent itself
subrecord.commit();

How do I include form data in email to SUBMITTER?

I am trying to include in the email notification to the submitter/user (person filling out the form) the form the data from the form that the put into the form.
I found this tutorial on including it in the email to myself as the owner of the form (http://www.labnol.org/internet/google-docs-email-form/20884/), and it works great, but I want to send that information to the person who filled out the form.
I have tried replacing this code:
var email = Session.getActiveUser().getEmail();
with this code:
var email = e.namedValues["Email Address"].toString();
That doesn't seem to be the trick. I double-checked the field name in the form/response spreadsheet, and it does match "Email Address." I also made that a required field in the form.
Could someone assist me with this?
you need to check the each column in iteration....
if the column is email - address column then you need to assign to email variable.
here you need to assign
for ( var keys in columns )
{
var key = columns[keys];
if(columns[keys] == "Email Address")
{
email = e.namedValues[key].toString();
}
if ( e.namedValues[key] && (e.namedValues[key] != "") )
{
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}

Symfony: question about the form filters

In the frontend I have a page with a list and a form filter next to it
that shows all the users of a social network.
I would like to hide the user of the session in that list. How can I
do it?
My first thought is creating a function, addXXXXColumnQuery(), for each
field of the form, and in each one add a line like this:
->andWhere("u.id <> ?", $id)
$id being the ID of the user of the current session. But in that way I
find I'm repeating myself.
What should I do?
First, you need to get the user into the filter. You have two options:
Pass the user_id in as an option when you instantiate the form, inside the action:
public function executeList(sfWebRequest $request)
{
$user_id = $this->getUser()->getUserId();
$filter = new ModelFormFilter(array(), array('user_id' => $user_id));
...
Get the user id from the context inside of the form:
sfContext::getInstance()->getUser()->getUserId();
I prefer the former method because it's cleaner and less WTFy.
Once you have the user id, override doBuildQuery to exclude the current user id inside of your FormFilter:
protected function doBuildQuery(array $values)
{
$query = parent::doBuildQuery($values);
$user_id = $this->getOption('user_id'); //or off the context here
if ($user_id)
{
$query->addWhere('r.user_id != ?', $user_id);
}
return $query;
}

Drupal 6: Modifying uid of a submitted node

I have a situation where I want a set of users (employees) to be able to create a node, but to replace the uid (user ID) with that of the users profile currently displayed.
In other words, I have a block that that calls a form for a content type. If an employee (uid = 20) goes to a clients page (uid =105), and fills out the form, I want the uid associated with the form to be the client's(105), not the employee's.
I'm using arg(1) to grab the Client's uid - here is what I have..
<?php
function addSR_form_service_request_node_form_alter(&$form, $form_state) {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$form['#submit'][] = 'addSR_submit_function';
}
}
function addSR_submit_function($form, $form_state) {
$account = user_load(arg(1));
$form_state['values']['uid'] = $account->uid;
$form_state['values']['name'] = $account->name;
}
?>
The form is loading in the block, but when submitted, is still showing the employee uid. I don't want to use hook_form_alter because I don't want to modify the actual form, because clients can fill out the form directly, in this case, I don't want to modify the form at all.
I'm also ashamed that I'm putting this in a block, but I couldn't think of a way to put this in a module, so any suggestions on that would also be appreciated...
To create your form in a block, you could use the formblock module. Especially if you are not used to use the Drupal API. Then all that's left if to add your own submit handler to the form. This is a piece of code that is run, when the form is submitted. You only want to do this on clients pages so you would do that using the hook_form_alter function.
/**
* Hooks are placed in your module and are named modulename_hookname().
* So if a made a module that I called pony (the folder would then be called
* pony and it would need a pony.info and pony.module file I would create this function
*/
function pony_form_service_request_node_form_alter(&$form, $form_state) {
// Only affect the form, if it is submitted on the client/id url
if (arg(0) == 'client' && is_numeric(arg(1))) {
$form['#submit'][] = 'pony_my_own_submit_function';
}
}
function pony_my_own_submit_function($form, &$form_state) {
$account = user_load(arg(1));
$form_state['values']['uid'] = $account->uid;
$form_state['values']['name'] = $account->name;
}
The idea behind this code, is to only alter the form when the condition is met - that it is submitted on a client page. I guessed that the arg(0) would be client so if it's something else you would need to change that of cause. We only need to add a submit function, since what we want is to change the values if the form has passed validation.
Then if that is the case our 2nd function is run, which does that actual alteration of the values.
PHP blocks are bad. You can put them in a module.
function hook_block($op, $delta = 0) {
// Fill in $op = 'list';
if ($op == 'view' && $delta = 'whatever') {
$account = user_load(arg(1));
$node = array('uid' => $account->uid, 'name' => $account->name, 'type' => 'service_request', 'language' => '', '_service_request_client' => $account->uid);
$output = drupal_get_form('service_request_node_form', $node);
// Return properly formatted array.
}
}
Additionally, you want a form_alter just to enforce the values. It's ugly but it works.
function hook_form_service_request_node_form_alter(&$form, $form_state) {
if (isset($form_state['node']['_service_request_client'])) {
$form['buttons']['submit']['#submit'] = array('yourmodule_node_form_submit', 'node_form_submit');
}
}
function yourmodule_node_form_submit($form, &$form_state) {
$account = user_load($form_state['node']['_service_request_cilent'])l
$form_state['values']['uid'] = $account->uid;
$form_state['values']['name'] = $account->name;
}