Search Engine in URL issue
2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 3, 2012 (RSS)
By benedict - July 3, 2012
Hi guys,
I have a search form in my website that works fine using the custom search form/search engine method mentioned on http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html
It is working fine except...
In CMSB, an activitity is related to a State and the to one of that state's related Regions. When a user selects a state, they need to select a region. This all works fine.
On the front end, I am trying to replicate this - i.e. a user selects a state and then, if they like, a region (non-mandatory).
I have created the JQuery method of the relevant region field appearing, dependent on the user's State selection. My problem is that I have had to name each of the 9 different region fields "region" so that the search engine will work (see below). Problem is that when I click submit, it picks up the region field 9 times and screws up the search results. Am I allowed to name the field something else?:
I have a search form in my website that works fine using the custom search form/search engine method mentioned on http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html
It is working fine except...
In CMSB, an activitity is related to a State and the to one of that state's related Regions. When a user selects a state, they need to select a region. This all works fine.
On the front end, I am trying to replicate this - i.e. a user selects a state and then, if they like, a region (non-mandatory).
I have created the JQuery method of the relevant region field appearing, dependent on the user's State selection. My problem is that I have had to name each of the 9 different region fields "region" so that the search engine will work (see below). Problem is that when I click submit, it picks up the region field 9 times and screws up the search results. Am I allowed to name the field something else?:
<li>
<select name="state" id="state">
<option value="">-- Select A State --</option>
<?php foreach ($activity_statessearchRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
<fieldset id="1">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiesintRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="2">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiesvicRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="3">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiesnswRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="4">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiesqldRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="5">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citieswaRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="6">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiessaRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="7">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiestasRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="8">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiesntRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<fieldset id="9">
<li>
<select name="region">
<option value="">-- Select Region --</option>
<?php foreach ($activity_citiesactRecords as $record): ?>
<option value="<?php echo $record['num'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach ?>
</select>
</li>
</fieldset>
<script type="text/javascript">
jQuery('select[name=state]').change(function(){
var fieldsetName = $(this).val();
$('fieldset').hide().filter('#' + fieldsetName).show();
});
// We need to hide all fieldsets:
$('fieldset').hide();
</script>
Re: [benedict] Search Engine in URL issue
By Jason - July 3, 2012
Hi,
Yes, you are allowed to give fields the same name. When a form submits, the name of the field becomes an index in the $_REQUEST array. If you have multiple fields with the same name, you end up overwriting these values. The value you are probably getting is the value of your last region box.
The best option here would be to have a single region box, whose options are updated based on a state selection. You can do this with the jquery get() function:
http://api.jquery.com/jQuery.get/
If this doesn't work, you can try using display block and display none to try to keep multiple values from submitting
example:
Hope this helps
Yes, you are allowed to give fields the same name. When a form submits, the name of the field becomes an index in the $_REQUEST array. If you have multiple fields with the same name, you end up overwriting these values. The value you are probably getting is the value of your last region box.
The best option here would be to have a single region box, whose options are updated based on a state selection. You can do this with the jquery get() function:
http://api.jquery.com/jQuery.get/
If this doesn't work, you can try using display block and display none to try to keep multiple values from submitting
example:
$('#' + fieldsetName).css('display', 'block');
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/