Page 1 of 1

FormBuilder: Submit to an arbitrary form action [SOLVED]

Posted: Tue Aug 03, 2010 5:38 am
by antosha
Hi,
I want to send formbuilder form's values via URL (ex: http://mysite.com/somepage.html?variabl ... le2=value2)

That means I need to find a way to submit form data using the "GET" method, like this:

Code: Select all

<form action="somepage.html" method="get">
 
The problem is, I don't think it's possible to change formbuilder's default "post" method to "get" (unless I force it by replacing {$fb_form_start} with

Code: Select all

<form id="cntnt01moduleform_1" method="get" action="http://mysite.com/index.php" enctype="multipart/form-data">
but that doesn't please me since that way the form sends the values of all the fields.

So, I found the "Submit to an arbitrary form action" field which lets me chose between Get or Post methods,  action submit page and which fields I want to include. However, it doesn't seem to work...

Can someone show me the way out? :)

Thanks

Re: FormBuilder: Submit to an arbitrary form action

Posted: Tue Aug 03, 2010 8:14 pm
by antosha
SOLVED, thanks to Thanaton on IRC#cms :)

Re: FormBuilder: Submit to an arbitrary form action [SOLVED]

Posted: Fri Aug 13, 2010 11:52 am
by palun
Can you please show us the solution? (I have a similar problem...)
/ulf

Re: FormBuilder: Submit to an arbitrary form action [SOLVED]

Posted: Fri Oct 15, 2010 6:15 pm
by sleven1868
I'm having the same issue.  Can you post your solution please?  Thanks!

SOLUTION

Posted: Fri Feb 11, 2011 7:51 pm
by antosha
Hi everyone,
Sorry for posting so late, I was quite busy in the past few months and not very active in the forums :)
I 've got many request for sharing the solution so here is how it works.

First of all, forget about the "Send to arbitrary action" function since it doesn't seem to work.
After you created your form in formbuilder , make sure that that your fields have a unique alias.
So, let's say one of my text input field alias is "myfield1" and the other one is "myfield2"

After that we are going to create a UDT:
Since we have more than one field data to output, we need to create a new array call it $temp_url.

Code: Select all

$temp_url = array();
Let's populate the array with our formbuilder field data. Were are going to use the .urlencode PHP function to adapt the data for URL formatting.

Code: Select all

if(isset($params['myfield1'])){
	$temp_url[] = 'myfield1=' . urlencode($params['myfield1']);
}

if(isset($params['myfield2'])){
	$temp_url[] = 'myfield2=' . urlencode($params['myfield2']);
}
Finally we are going to incorporate our data array into our URL and redirect the page with an HTTP header. In this example I assume the page alias that receives your data is called "form-results".

Code: Select all

$url = 'http://mysitename.com/form-results?' . implode($temp_url, '&');
	header('Location: ' . $url);
	exit();
So your UDT should look like this, I added an if statement for debugging in case something went wrong:

Code: Select all

$temp_url = array();

if(isset($params['myfield1'])){
	$temp_url[] = 'myfield1=' . urlencode($params['myfield1']);
}

if(isset($params['myfield2'])){
	$temp_url[] = 'myfield2=' . urlencode($params['myfield2']);
}

if(count($temp_url)){
	$url = 'http://mysitename.com/form-results?'' . implode($temp_url, '&');

	header('Location: ' . $url);
	exit();
}else{
	echo "Houston we've got a problem. Wrong params!";

	var_dump($params);
}
Name this UDT "form_redirect".

Go back to Formbuilder, add a *Call A User Defined Tag With the Form Results, select "form_redirect".

Make sure to check this:
Export form reference to UDT as $params['FORM']? (do not do this if you are going to print_r($params) ):
Save the whole thing.
Try your form. After submit, it should redirect you to http://mysitename.com/form-results/?field1=[field1 data]&field2=[field2 data]

Now, if you want to use your form data on your page, use the GET function.

Code: Select all

{$smarty.get.field1}
{$smarty.get.field2}
That's about it.
I hope this helps !

Re: FormBuilder: Submit to an arbitrary form action [SOLVED]

Posted: Fri Feb 11, 2011 8:41 pm
by mr.bacan
Thanks a lot for posting your solution. I'll give it a try.