Forums

Copy form input values to hidden field

clinden 09 May, 2011
Hi

Is is possible that after a users has filled out the form some of the data for example name, email and address is grouped together and put in a hidden field ?

I know it sounds a bit odd and please let me know if I am not making sense but I am trying to populate a field in my CRM system and would like to group a set off values together and populate just one field.

Many thanks !
GreyHead 09 May, 2011
Hi clinden,

You can do that in the OnSubmit Before Email box (requires Send Emails set to Yes in the form General tab).

Can you say a bit more about the format you need? the CURL plug-in migh help.

Bob
clinden 09 May, 2011
I am using the curl plugin at the moment sending all form data to our crm system. So if possible grouping three fields address,zip and country for example together and place them in a hidden field, then I can do a mapping of the hidden field and the correct field in the crm system using the curl plugin.

Cheers and thanks!
GreyHead 09 May, 2011
Hi clinden,

Here's a rough code snippet. It should work in the OnSubmit Before Email box or the Before cURL box in the plug-in configuration.

First add a hidden placeholder input to the Form HTML. This is just to force the cURL Plug-in to create an input box for this variable.
<input type='hidden' name='input_string' id='' value='' /> 

Then the main code is:
<?php
$inputs = array(
  'address' => '',
  'zip' => '',
  'country' => ''
);
foreach ( $inputs as $k => $v ) {
  $inputs[$k] = JRequest::getString($k, '', 'post');
}
$input_string = implode('#', $inputs);
JRequest::setVar('input_string', $input_string);
?>
Change the array and implode lines to match your requirements.

Bob
clinden 09 May, 2011
Many thanks again for the amazing support. The code works brilliant !

Cheers

//C
clinden 04 Jul, 2011
Can I still use this code to group two date fields and add them both to a hidden field ? Do I need to change getString to getInt anything else I need to change ?

Cheers

//Carl
GreyHead 04 Jul, 2011
Hi clinden,

You can save more than one value or you can join strings. No need to change anything; the getString and getInt are validation filters to clean the form data. Dates are going to be strings.

Bob
clinden 04 Jul, 2011
Hi

I have tried to change the input values but nothing is showing in the debug screen (no value).

CONTACTCF130=&CONTACTCF91=2011%2F07%2F04&


Current extra code in the curl section:

<?php
$inputs = array(
  'custom_date_1' => '',
  'custom_date_2' => ''
  );
foreach ( $inputs as $k => $v ) {
  $inputs[$k] = JRequest::getString($k, '', 'post');
}
$input_string = implode(' ', $inputs);
JRequest::setVar('input_string', $input_string);


$input_string is set to populate CONTACTCF130

What I am doing wrong ?

Cheers
GreyHead 04 Jul, 2011
Hi clinden,

The code looks OK to me. I'd add some temporary debug statements to echo out the internediate result to see what is happening.
<?php
global $mainframe;
$inputs = array(
  'custom_date_1' => '',
  'custom_date_2' => ''
  );
foreach ( $inputs as $k => $v ) {
  $mainframe->enqueuemessage('$k: '.print_r($k, true).'<hr />');
  $inputs[$k] = JRequest::getString($k, '', 'post');
}
$input_string = implode(' ', $inputs);
$mainframe->enqueuemessage('$input_string: '.print_r($input_string, true).'<hr />');
JRequest::setVar('input_string', $input_string);

Bob
This topic is locked and no more replies can be posted.