FormBuilder: Submit to an arbitrary form action [SOLVED]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

FormBuilder: Submit to an arbitrary form action [SOLVED]

Post 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
Last edited by antosha on Fri Feb 11, 2011 7:54 pm, edited 2 times in total.
Follow me on twitter: end_tone
Linked In: levchenkoanton
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: FormBuilder: Submit to an arbitrary form action

Post by antosha »

SOLVED, thanks to Thanaton on IRC#cms :)
Follow me on twitter: end_tone
Linked In: levchenkoanton
palun
Forum Members
Forum Members
Posts: 43
Joined: Sun Aug 02, 2009 9:08 am

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

Post by palun »

Can you please show us the solution? (I have a similar problem...)
/ulf
sleven1868
New Member
New Member
Posts: 9
Joined: Thu Jul 22, 2010 4:54 pm

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

Post by sleven1868 »

I'm having the same issue.  Can you post your solution please?  Thanks!
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

SOLUTION

Post 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 !
Follow me on twitter: end_tone
Linked In: levchenkoanton
mr.bacan

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

Post by mr.bacan »

Thanks a lot for posting your solution. I'll give it a try.
Post Reply

Return to “Modules/Add-Ons”