Hi, I've tried the rest of the forums but no joy and I'm running out of time with this so..
I'm trying to make a custom search page where there is a defined list of keywords that can be choosen to then perform a text search of the site.
I'm using trip_search module, and have been trying to create a form that will combine values to be post to the module.
I have tried two ways of achieving this.
Firstly, a list of checkboxes (sharing the same controlname NAME="edit[require]" ) but I'm only getting the last ticked checkbox is searched for.
See:
<form action="/trip_search" method="post" id="trip_search_form">
<input name="edit[form_id]" id="edit-trip-search-form" value="trip_search_form" type="hidden">
<input name="edit[form_token]" id="edit-form_token" value="<?php print drupal_get_token('trip_search_theme_form'); ?>" type="hidden">
<fieldset>
<label><input type="checkbox" name="edit[require]" id="checkbox1" value="user" />
User</label>
<label>
<input type="checkbox" name="edit[require]" id="checkbox2" value="doctor" />
Doctor</label>
<label>
<input type="checkbox" name="edit[require]" id="checkbox3" value="army" />
Army</label>
<label>
<input type="checkbox" name="edit[require]" id="checkbox4" value="alcohol" />
Alcohol</label>
</fieldset>
<input maxlength="200" name="edit[keys]" id="edit-keys" size="30" value="" class="form-text" type="text" />
<label>
<input name="edit[form_type]" id="edit-form_type" value="search" type="hidden">
<input name="op" value="Search" class="form-submit" type="submit">
</label>
</p>
</form>
Second approach, I tried a javascript solution where clicking on keyword buttons inserts the keyword into an input textarea that is then search with. Javascript doesn't like the PHP use of the square brackets.
eg.
(onClick="this.form.forms[0].value=this.form.forms[0].value.concat('TRIP ');)
The form is:
<form action="/trip_search" method="post" id="trip_search_form">
<input name="edit[form_id]" id="edit-trip-search-form" value="trip_search_form" type="hidden">
<textarea name="edit[require]" rows=10 cols=50 wrap=virtual>
</textarea>
<BR>
<INPUT TYPE="button" NAME="insert" VALUE="BOLD" onClick="this.form.edit[require].value=this.form.edit[require].value.concat('BOLD ');">
<INPUT TYPE="button" NAME="insert" VALUE="TRIP" onClick="this.form.edit[require].value=this.form.edit[require].value.concat('TRIP ');">
<input name="edit[form_type]" id="edit-form_type" value="search" type="hidden">
<input name="op" value="Search" class="form-submit" type="submit">
</FORM>
I have tried onClick="this.form.\"edit[require]\".value=this.form.\"edit[require]\".value.concat('TRIP ')
and this doesn't work either
I don't know PHP or javascript and so have been guessing all this.
What I want is someone knowledgable in the PHP forms solution or the javascript and PHP fields solution to save my bacon with this.
Thanks for any help!
Comments
ooh!
can I get extra credit for answering both questions? ;)
the php-way: you've made 'edit' into an array with an element called 'require', but now you need to make require an array as well.
change all your
name="edit[require]"toname="edit[require][]"and you should see a result like this:your javascript has a similar problem, as you noticed it doesn't like having [] in the variable name. there's an alternate syntax you can use when the variable has strange characters in the name, like this:
this.form.edit[require].value=this.form["edit[require]"].value.concat('BOLD ');hope that helps, please contact me through this site :)
Thanks but if only..
..it would work
I had tried this already and unfortunately both ways don't do anything.
I imagine "edit[require]" in the javascript is getting dropped because the "" is recognised in the html code as the end of the string.
The multidimensional array for PHP name="edit[require][]" doesn't work and I haven't a clue why not.
I really need a solution soon on this.
The website is http://insidestories.org/
you can see my attempts in the blocks below the main content using the different methods.. no joy
Maybe with the javascript I need to link to an external script but again I don't know much about scripting.
javascript
you're right, its because the " is part of the string.
try this instead:
I used the following code that worked fine in FF2,
after you submit the form it will show what was submitted.
As for the PHP solution, I used the following test page, and it worked great for me. Can you post your code, or say what error you are getting?
Nice one!
Thanks krsz!
The corrected javascript version works well thankyou.
The php version still doesn't, I'm testing it by pasting the code into a block (no filters) and then using it.
The admin log for this event says 0 matches for "Array".
The code is same as yours except for action="/trip_search"
You can see what it does on the site under the 'PHP checkboxes solution' block at the bottom of the page.
My ideal solution is the PHP one with the checkboxes (because they can be easily unchecked)
Can you help get this method working?
Could you private message me and we can arrange payment anyway.