Forums

Concatenate fields before submit

Zeon 11 Mar, 2009
Hey guys,
I have a form which has 4 fields. Basically I want to concatenate these all with a space in between before submitting another variable called "keyword" to a POST URL.

If you have a look at this website:
http://www.gotyres.co.nz

The calculator basically needs to join all the fields then submit to the search form on the right (which is for virtuemart). E.g.
205/50R16 87V

width: 205
profile: 50
tyre size: 16
speed rating: v

would concatenate to 205 50 16 v

This would then post to the action on the form on the right hand side. Ideas?
GreyHead 11 Mar, 2009
Hi Zeon,

I guess that a JavaScript snippet could do this for you, or you could easily do it serverside in PHP before redirecting with the REDirect URL.

What do you actually want to receive in VirtueMart (are you going to separate out the pieces again there?) and are you transferring with GET using a url or POST using form variables.

Bob

PS You can't put a space in a URL, you'll probably need %20 instead.
Zeon 11 Mar, 2009
hi Bob,
Thanks for the reply. Yup I think your right. What I have tried to do is put this code in chronoforms in the field:
"On submit code - before sending email":

$_POST['keyword'] = $_POST['width'] . ' ' . $_POST['profile'] . ' ' . $_POST['tyre_size'] . ' ' . $_POST['speed_rating']


it doesn't seem to work however. unfortunately I'm not a coder so just going on others suggestions at the moment!

And sorry - to answer your questions there are no spaces in the URL, just in the keyword field.


Thanks,
Jonathan
nml375 12 Mar, 2009
The problem there is that your search-form is a completely different form.
What you could do, is to add a manual redirect pointing at the url "http://www.gotyres.co.nz/index.php/View-all-products-in-shop.html?keyword=<value-here>".
Code would be something like this:
<?
$t =& JFactory::getApplication('site');
$t->initialise();
$q = array('keyword' => $_POST['width'] . ' ' . $_POST['profile'] . ' ' . $_POST['tyre_size'] . ' ' . $_POST['speed_rating']);
$u = new JURI('http://www.gotyres.co.nz/index.php/View-all-products-in-shop.html');
$u->setQuery($u->buildQuery($q));
$t->redirect($u->toString());
?>


Though, you really should considder replacing $_POST[] with JRequest::getVar().

Edit: Fixed proper reference-assignment, making the code more "kosher".
This topic is locked and no more replies can be posted.