Iam new to modx(revolution version 2.5.7) and simple search(simplesearch-1.9.2-pl)
I need to add date dropdown (need to fetch results with matching date which is a template variable as type date ) with simplesearch extra in modx plugin. I have attached screenshot of my searchpage for reference. Please help me to solve this.
https://forums.modx.com/thread/95128/advsearch-to-show-search-value-based-on-dropdown-box.
After many painful debugging , got my code working.
[b]My code[/b] ,
[[!AdvSearchForm? &tpl=`AdvanceSearchForm_tpl`]]
</h1>
<h2>Results</h2>
<p>[[!AdvSearch? &parents=`12`&queryHook=`FilterCalenderSnippet` ]]
[b]form tpl (AdvanceSearchForm_tpl) :--[/b]
[code]<form id="[[+advsearch.asId]]_advsea-form" class="advsea-form" action="[[~[[+advsearch.landing]]]]" method="[[+advsearch.method]]">
<fieldset>
<input type="hidden" name="id" value="[[+advsearch.landing]]" />
<input type="hidden" name="asId" value="[[+advsearch.asId]]" />
[[+advsearch.helpLink]]<input type="text" id="[[+advsearch.asId]]_advsea-search" name="[[+advsearch.searchIndex]]" value="[[+advsearch.searchValue]]" />
[[$SeminarCalendarDateChunk]]// give the dropdown of dates,you can put your form elements
[[+advsearch.liveSearch:isnot=`1`:then=`<input type="submit" id="[[+advsearch.asId]]_advsea-submit" name="sub" value="[[%advsearch.search? &namespace=`advsearch` &topic=`default`]]" />`:else`=``]]
</fieldset>
</form>
[[+advsearch.resultsWindow]]
[b]Query Hook snippet(FilterCalenderSnippet)[/b]
[ul]
[li]My Date tv is EventDateTv[/li]
[/ul]
[code]
<?php
$andConditions = array();
// here i need to show events between one given input month. so I did some php to fetch first and last days of given month
if (!empty($_REQUEST['calendar_date'])) {
$dateToTest = $_REQUEST['calendar_date'];// my form element name is calendar_date
$lastday = date('Y-m-t',strtotime($dateToTest));
$andConditions['tv.EventDateTv:>='] = $dateToTest;
$andConditions['tv.EventDateTv:<='] = $lastday ;
}
if (!empty($andConditions)) {
$qhDeclaration = array(
'qhVersion' => '1.3',
'andConditions' => $andConditions
);
$hook->setQueryHook($qhDeclaration);
}
return true;
[/code]`enter code here`
Related
This may be a basic question, but I'm struggling. Essentially I have a livewire component that updates an array of flight information that a user enters. Whenever the components get rerendered, the flatpickr functionality stops working entirely. I presume this is because the javascript to initialize the component on that field is not running. What is the best practice to ensure these get rerendered with the appropriate javascript to enable the functionality.
Here's my blade snippet which renders fine on the initial load, but whenever a change to the data occurs, the page re-renders all the flights in the array, but the flatpickr functionality does not work anymore.
<form>
#foreach($flights as $i => $f)
<label
x-data
x-init="flatpickr($refs.input, {
dateFormat: 'Y-m-d H:i',
altInput: true,
altFormat: 'F j, Y h:i K',
enableTime: true,
})">
<div class="form-label">Arrival Time</div>
<div class="relative">
<input type="text"
wire:model="flights.{{ $i }}.ArrivalTime"
wire:key="fl{{ $i }}arrtime"
data-input
x-ref="input"
placeholder="Arrival Time"
value="{{ $f['ArrivalTime']}}"
name="flights[{{ $i }}][ArrivalTime]"
id="ArrivalTime{{$i}}"
/>
</div>
</label>
#endforeach
</form>
The livewire component is basically this:
class Itinerary extends Component
{
public $itin = null;
public $flights = [];
public function render()
{
return view('livewire.itinerary');
}
}
You need to wrap the input in a <div> like this:
<div wire:ignore>
<!-- Your input here -->
</div>
Source: https://laravel-livewire.com/docs/2.x/alpine-js#ignoring-dom-changes
I'm using the TYPO3 version 8, I have installed the indexed_search form box with typoscript
50 = COA
50 {
stdWrap {
wrap = <div id="searchcontainer">|</div><div class="clearboth"></div>
required = 1
}
10 = TEXT
10 {
wrap = <form id="searchbox" name="searchbox" action="|" method="post">
typolink.parameter = {$searchPID}
typolink.returnLast = url
if.isTrue = {$config.tx_realurl_enable}
}
20 = TEXT
20 {
value = <form id="searchbox" name="searchbox" action="/" method="post">
if.isFalse = {$config.tx_realurl_enable}
}
30 = COA
30 {
10 = TEXT
10{
wrap = <input type="hidden" name="id" value="|" />
value = {$searchPID}
if.isFalse = {$config.tx_realurl_enable}
}
20 = TEXT
20 {
wrap = <input type="text" id="swords" name="swords" value="|" size="20" onfocus="this.value='';" />
value = {$searchTEXT}
}
30 = TEXT
30 {
wrap = <input type="submit" id="searchbutton" value="" />
}
}
40 = TEXT
40 {
value = </form>
}
}
When I click on search, I'm redirected to my search page wich contain the search plugin installed, but no search results or even the keyword is showing. The pages are well indexed and in the backend indexing searched keyword it appears, but not in the frontend, what I'm mising here ? please help!
user2714261 shows, how to deactivate the cHash check for all elements. That might a bit risky in deed. But you can deactive it only for the indexed_search plugin. That won't be any problem, because the indexed_search should not cache anyway. So you jsut can write in your plugin-Setup:
plugin {
tx_indexedsearch {
features.requireCHashArgumentForActionArguments = 0
}
}
That worked fine in TYPO3 8.7.9.
Martin
You can use <f:form> in a FLUIDTEMPLATE to generate a Quicksearch-Form. This way an essential cHash-parameter will be generated and appended to the action-URL, automatically.
TypoScript (Constants)
plugin.tx_indexedsearch.settings.targetPid = 35
TypoScript (Setup)
lib.quicksearch = FLUIDTEMPLATE
lib.quicksearch{
file = fileadmin/Quicksearch.html
settings.targetPid = {$plugin.tx_indexedsearch.settings.targetPid}
}
Quicksearch.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div id="quicksearch">
<f:form action="search" method="post" controller="Search" extensionName="indexedsearch" pluginName="pi2" pageUid="{settings.targetPid}">
<f:form.textfield name="search[sword]" value="{sword}" class="quicksearch-sword" />
<f:form.submit name="search[submitButton]" value="Search" class="quicksearch-submit" />
</f:form>
</div>
</html>
Edit: i found the solution. You have to add something to the typolink ts (my result plugin has _pi2 btw)
wrap = <form id="searchbox" name="searchbox" action="|" method="post">
typolink.parameter = 25
typolink.additionalParams = &tx_indexedsearch_pi2[action]=search&tx_indexedsearch_pi2[controller]=Search
typolink.returnLast = url
typolink.useCacheHash = 1
First Posting:
I don't have the solution right now, but i found something that could help.
I'm having a similar problem with TYPO3 8 and a searchbox. I adapted my HTML of the searchbox, that it fits to the embedded plugin, like this:
<form action="searchresult.html?tx_indexedsearch_pi2%5Baction%5D=search&tx_indexedsearch_pi2%5Bcontroller%5D=Search" method="post" name="searchform" id="searchform">
<input name="tx_indexedsearch_pi2[search][sword]" type="text"/>
<input name="tx_indexedsearch_pi2[search][submitButton]" type="submit" id="submitbutton" value="submit"/>
...
As you can see i have a fixed setup here in my template. What i noticed is, that the embedded plugin obviously doesn't run if you don't send the chash in the action url. Probably you can generate it with your typoscript.
I'm just sure that this is the problem, at least for my case, because when i turn the chash requirements for extbase off, it works ...
config.tx_extbase.features.requireCHashArgumentForActionArguments = 0
but i believe that is a little bit risky and should not be used in production
so generating the chash should be the way to do make it work. just wanted to share what i found out.
Hi I hope someone can help on the client details page I need to hide the Email forwarding button and the DNS management button if the client has selected custom nameservers. I just can't work it out son any help is much welcomed ..Here is the code that takes the input;
<form method="post" action="{$smarty.server.PHP_SELF}?action=domaindetails">
<input type="hidden" name="sub" value="savens">
<input type="hidden" name="id" value="{$domainid}">
<p><input type="radio" name="nschoice" value="default" id="nschoicedefault" onclick="usedefaultns()"{if $defaultns} checked{/if} /> <label for="nschoicedefault">{$LANG.nschoicedefault}</label><br />
<input type="radio" name="nschoice" value="custom" id="nschoicecustom" onclick="usecustomns()"{if !$defaultns} checked{/if} /> <label for="nschoicecustom">{$LANG.nschoicecustom}</label></p>
And here is the code for the buttons;
{if $emailforwarding}
<td><form method="post" action="{$smarty.server.PHP_SELF}?action=domainemailforwarding">
<input type="hidden" name="domainid" value="{$domainid}">
<p align="center">
<input type="submit" value="{$LANG.domainemailforwarding}" class="button">}
</p>
</form></td>
{/if}
{if $dnsmanagement}
<td><form method="post" action="{$smarty.server.PHP_SELF}?action=domaindns">
<input type="hidden" name="domainid" value="{$domainid}">
<p align="center">
{<input type="submit" value="{$LANG.domaindnsmanagement}" class="button">}
</p>
</form></td>
{/if}
I suggest writing a helper function and calling it at the top of the tpl file
and passing the domain id to it.
You can then use the WHMCS internal API function Domain Nameservers to get the domains nameservers then compare them against the default nameservers in the tblconfiguration in the WHMCS database.
Something like this
{php}
// include our helper php file
require_once(dirname(__FILE__).'/Helper.php');
//get domain id from our template variables
$domainid = $this->get_template_vars('domainid');
//call to our helper function passing the domain ID
$hasCustomeNameServers = Helper::hasCustomNameServers($domainid);
//Once we've compared the nameservers agains the default ones we write
//our binary check to the template
if($hasCustomeNameServers >0){
$this->assign('hasCustomeNameServers',true);}
{/php}
Then in side our Helper.php we have something like the following
<?php
class Helper {
public static function hasCustomNameServers($domainid) {
$isCustom = 0;
//Interal API call to get the domains nameservers
$command = "domaingetnameservers";
$adminuser = "admin";
$values["domainid"] = $domainid;
$results = localAPI($command,$values,$adminuser);
//get default nameservers
$defautName1 ='';
$sql = mysql_query('SELECT value FROM tblconfiguration '.
' WHERE setting = "DefaultNameserver1"');
if ($res = mysql_fetch_assoc($sql)) {
$defautName1 = $res["value"];}
$defautName2 ='';
$sql = mysql_query('SELECT value FROM tblconfiguration '.
' WHERE setting = "DefaultNameserver2"');
if ($res = mysql_fetch_assoc($sql)) {
$defautName2 = $res["value"];}
//compare results
foreach ($results as &$value) {
if($value == $defautName1 || $value == $defautName2){
$isCustom++;
}
}
return $isCustom;
}
}
Now it's simply a matter on the template to wrap the {if $emailforwarding} and the {if $dnsmanagement} blocks around our check {if !hasCustomeNameServers}
I hope this helps you in the right direction this is by no means a comprehensive answer but is a guide towards the approach I think you should take in implementing your solution.
I'm using the following code to populate a WordPress dropdown menu with all the unique values from a custom field:
<form name="search" action="" method="get">
<select name="stateprov">
<option>Select...</option>
<?php
$metakey = 'state_prov';
statesProvs = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($statesProvs) {
foreach ($statesProvs as $stateprov) {
echo "<option value=\"" . $stateprov . "\">" . $stateprov . "</option>";
}
}
?>
</select>
<input type="submit" value="search" />
</form>
However, it takes nothing from the DB so the popup list is empty.
Trying a different query like
$statesProvs = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_author = 2" );
Works as expected. I get a popup with a bunch of Post ID's in it. But the query that's supposed to work on my custom metadata just brings up an empty menu (and print_r reveals an empty array).
The data is definitely in the DB... what am I doing wrong?
It may also be significant that I'm using a custom metabox PHP class that writes all the custom-created field keys and values into the value of the _custom_meta metakey. If I've put that correctly. Thus:
a:61:{s:10:"state_prov";s:2:"CA";s:13:"vertical_drop";s:13:"3100ft / 945m";s:14:"base_elevation";s:14:"7953ft / 2424m";s:16:"summit_elevation";s:15:"11053ft / 3369m";s:12:"skiable_area";s:10:"3500 acres";s:16:"average_snowfall";s:14:"400in / 1016cm";s:13:
Etc. Is this way of storing the custom metadata preventing wpdb from accessing it properly?
Thanks!
you must use global $wpdb before you start the wpquery, refer codex for more details
<form name="search" action="" method="get">
<select name="stateprov">
<option>Select...</option>
<?php
global $wpdb;
$metakey = 'state_prov';
$wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($statesProvs) {
foreach ($statesProvs as $stateprov) {
echo "<option value=\"" . $stateprov . "\">" . $stateprov . "</option>";
}
}
?>
</select>
<input type="submit" value="search" />
</form>
Etc. Is this way of storing the custom metadata preventing wpdb from
accessing it properly?
Yes.
In general, Wordpress isn't capable of searching or sorting through serialized PHP arrays.
The most viable solution here is to store this data point ('state_prov') in its own custom field. This will allow you to naturally search and sort using $wpdb. It also seems like you want this custom field to be private/hidden, in which case you'll want to prefix it with an underscore: '_state_prov'.
Another option, assuming the above isn't viable for your needs, is to use MySQL String Functions; but this is far from ideal or optimized (especially if the database grows significantly.) Rough, untested example below.
// Assuming all state_prov are exactly 2 characters in length
$identifier = 's:10:"state_prov";s:2:"';
$identifier_length = strlen($identifier);
$wpdb->get_col($wpdb->prepare("SELECT DISTINCT(SUBSTR(`meta_value`, INSTR(`meta_value`, '$identifier')+$identifier_length, 2)) as `state_prov` FROM $wpdb->postmeta WHERE `meta_key`=%s ORDER BY `state_prov` ASC", $metakey) );
I have a photography site driven in part by the 'Photoshelter' service, and I put an embedded search bar in my nav.
<form action="http://brettcole.photoshelter.com/search" method="get">
<input type="text" placeholder="search library" size="15" name="I_DSC">
<input type="submit" value="go">
<input type="hidden" name="I_DSC_AND" value="t">
<input type="hidden" name="_ACT" value="search">
</form>
It allows for a search to be executed with the no search term present, which then returns all 12,000 photos in my archive. Is there a best practice for preventing this, such that the user has to type something or nothing will happen when they click search?
It's also present on my advanced search page. This is generated by a search widget shortcode in the Photoshelter back end. I'd like to apply the same thing here, but not sure how the widgetization of it might affect the process.
Many thanks
You can use the onsubmit attribute of the form element to check if the user has entered information in any fields and then prevent submit based on that.
<script>
function checkValues() {
searchBox = document.getElementById("SearchField");
return searchBox.value != ""; // True will allow submission and false will prevent it
}
</script>
With this...
<form onsubmit="checkValues();" action="http://brettcole.photoshelter.com/search" method="get">
<input type="text" id="SearchField" placeholder="search library" size="15" name="I_DSC">
<input type="submit" value="go">
<input type="hidden" name="I_DSC_AND" value="t">
<input type="hidden" name="_ACT" value="search">
</form>
Should do what you need.
See also this answer: How to grab the onSubmit event for a form?
The actual search isn't working
From the contact page for example, it returns this
http://brettcolephotography.com/contact.html?I_DSC=red&I_DSC_AND=t&_ACT=search
the formula for my search returns is
http://brettcole.photoshelter.com/search?I_DSC=red&I_DSC_AND=t&_ACT=search
this search bar is present on all three of my web properties, personal site, blog, and photoshelter site, all three are tightly integrated to where you can't tell when you're switching between them. It needs to work regardless of where the search is being executed from. Thanks
Here is a function I wrote to disable the search form submitting if the search field is empty. It also focuses the cursor on the search field if the form is not submitted so that the user does not think that search is broken.
This is assuming that jQuery is loaded. Hope this helps!
var preventSearchIfEmpty = function() {
$('form[method="get"]').on( 'submit', function( ev ){
var query = $('input[type="text"]').val(),
queryLength = query.length;
if ( 0 === queryLength ) {
// Make the cursor blink so user is aware it's not broken, they need input to search
$('input[type="search"]').focus();
ev.preventDefault();
return;
}
});
}();