Laravel 8 Old Value in select - select

Im trying to get the selected category while validating inputs,
Please need help
in blade:
{{__("-- Please Select --")}}
category_id === $category->id)
$selected = 'selected';
printf("%s", $category->id, $selected, $prefix . ' ' . $category->name);
$traverse($category->children, $prefix . '-');
}
};
$traverse($tour_category);
?>
Thanks

Related

Woocommerce select country dropdown: how to remove default option and do not update_totals_on_change?

I have standard woocommerce select dropdown on checkout page with shipping_country and billing_country.
Can I remove first option with value=default using any hook? Or only by jQuery?
After the country have been changed woocommerce triggers an action updated_cart_totals. But I do not need it. To not trigger updated_cart_totals it is enough to remove update_totals_on_change class. Can I remove it using any hook? Or the same only by jQuery?
<p class="form-row form-row-wide address-field update_totals_on_change" id="shipping_country_field" data-priority="40">
<select name="shipping_country" id="shipping_country" class="country_to_state" autocomplete="country" tabindex="-1" aria-hidden="true">
<option value="default">Land/Region auswählen …</option>
<option value="BE">Belgien</option>
<option value="DE">Deutschland</option>
<option value="LU">Luxemburg</option>
<option value="NL" selected="selected">Niederlande</option>
</select>
</p>
UPDATE
1 question.
This is how fields are generated in form-shipping.php or form-billing.php:
foreach ( $fields as $key => $field ) {
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
}
Look in woocommerce_form_field code:
2726 function woocommerce_form_field( $key, $args, $value = null ) {
.....
2803 switch ( $args['type'] ) {
case 'country':
$countries = 'shipping_country' === $key ? WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries();
if ( 1 === count( $countries ) ) {
$field .= '<strong>' . current( array_values( $countries ) ) . '</strong>';
$field .= '<input type="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . current( array_keys( $countries ) ) . '" ' . implode( ' ', $custom_attributes ) . ' class="country_to_state" readonly="readonly" />';
} else {
$data_label = ! empty( $args['label'] ) ? 'data-label="' . esc_attr( $args['label'] ) . '"' : '';
2816 $field = '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="country_to_state country_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_attr__( 'Select a country / region…', 'woocommerce' ) ) . '" ' . $data_label . '><option value="">' . esc_html__( 'Select a country / region…', 'woocommerce' ) . '</option>';
foreach ( $countries as $ckey => $cvalue ) {
$field .= '<option value="' . esc_attr( $ckey ) . '" ' . selected( $value, $ckey, false ) . '>' . esc_html( $cvalue ) . '</option>';
}
$field .= '</select>';
$field .= '<noscript><button type="submit" name="woocommerce_checkout_update_totals" value="' . esc_attr__( 'Update country / region', 'woocommerce' ) . '">' . esc_html__( 'Update country / region', 'woocommerce' ) . '</button></noscript>';
}
break;
In the end of 2816 line we can see . '><option value="">' . esc_html__( 'Select a country / region…', 'woocommerce' ) . '</option>';
So 1st question solved - it is impossible to remove this option using any hook ((( only js/jQuery.
UPDATE
2 question.
Removing update_totals_on_change class can help not to updated_cart_totals only if we use select2 (selectwoo). If we deenqueue select2 then updated_cart_totals triggers every time select changed even without above class.
So the question is still how to disable that trigger on select country change?

Sort order list view by 'logged in user' in SuiteCRM

Removing default sort order in list view and sorting by 'Logged in user' in SuiteCRM.
Add the following code in custom/modules/Prospects(your module)/views/view.list.php
function listViewProcess() {
global $current_user;
$user_name = $current_user->user_name;
$id = $current_user->id;
$this->processSearchForm();
$this->params['custom_order_by'] = ' ORDER BY FIELD(assigned_user_id, "'.$id.'") DESC';
$this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
$savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
echo $this->lv->display();
}
custom_order_by will be considered as second order by field
so declare
$ret_array['order_by']=''; in include/ListView/ListViewData.php
before
$main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
Without customizing the code in include/listView/ListViewDate.php, just add the following code in custom/modules/(your module)/views/view.list.php
function listViewProcess() {
global $current_user;
$user_name = $current_user->user_name;
$id = $current_user->id;
$this->processSearchForm();
$this->params['overrideOrder']='1';
$this->params['orderBy']='1';
$this->params['custom_order_by'] = ' ORDER BY FIELD(accounts.assigned_user_id, "'.$id.'") DESC';
$this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
$savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
echo $this->lv->display();
}

Auto complete/Suggest in Wordpress Form

I'm placing a search form of 6 fields on my home page which includes a text box field named course. I want to show course suggestions while user typing. One more is, I want to show/hide some fields according to the option of first field dropdown. Any help would be appreciated.
You can use jQuery Auto Suggest which is included with WordPress : wp_enqueue_script
With this you can write a form that does a Ajax lookup to the the Ajax URL handler. Which you can add_action onto. AJAX in Plugins
So you can ajax lookup and then on the action side you can just perform a get_posts to match titles, or a raw sql Query. And return what is needed. edit your functions.php.
add_action('wp_enqueue_scripts', 'se_wp_enqueue_scripts');
function se_wp_enqueue_scripts() {
wp_enqueue_script('suggest');
}
add_action('wp_head', 'se_wp_head');
function se_wp_head() {
?>
<script type="text/javascript">
var se_ajax_url = '<?php echo admin_url('admin-ajax.php'); ?>';
jQuery(document).ready(function() {
jQuery('#se_search_element_id').suggest(se_ajax_url + '?action=se_lookup');
});
</script>
<?php
}
add_action('wp_ajax_se_lookup', 'se_lookup');
add_action('wp_ajax_nopriv_se_lookup', 'se_lookup');
function se_lookup() {
global $wpdb;
$search = like_escape($_REQUEST['q']);
$query = 'SELECT ID,post_title FROM ' . $wpdb->posts . '
WHERE post_title LIKE \'' . $search . '%\'
AND post_type = \'post_type_name\'
AND post_status = \'publish\'
ORDER BY post_title ASC';
foreach ($wpdb->get_results($query) as $row) {
$post_title = $row->post_title;
$id = $row->ID;
$meta = get_post_meta($id, 'YOUR_METANAME', TRUE);
echo $post_title . ' (' . $meta . ')' . "\n";
}
die();
}
Use ajax for both. You may have to write some mysql query to retrieve the required fields(post titles or whatever it is) from the table.

how to set a value for Zend_Form_Element_Submit (zendframework 1)

I have am having trouble setting the basic values of a zend form element submit button (Zendframework1). I basically want to set a unique id number in it and then retrieve this number once the button has been submitted.
Below is my code. you will nots that I tried to use the setValue() method but this did not work.
$new = new Zend_Form_Element_Submit('new');
$new
->setDecorators($this->_buttonDecorators)
->setValue($tieredPrice->sample_id)
->setLabel('New');
$this->addElement($new);
I would also appreciate any advice on what I use to receive the values. i.e what method I will call to retrieve the values?
The label is used as the value on submit buttons, and this is what is submitted. There isn't a way to have another value submitted as part of the button as well - you'd either need to change the submit name or value (= label).
What you probably want to do instead is add a hidden field to the form and give that your numeric value instead.
It's a little bit tricky but not impossible :
You need to implement your own view helper and use it with your element.
At first, you must add a custom view helper path :
How to add a view helper directory (zend framework)
Implement your helper :
class View_Helper_CustomSubmit extends Zend_View_Helper_FormSubmit
{
public function customSubmit($name, $value = null, $attribs = null)
{
if( array_key_exists( 'value', $attribs ) ) {
$value = $attribs['value'];
unset( $attribs['value'] );
}
$info = $this->_getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable, id
// check if disabled
$disabled = '';
if ($disable) {
$disabled = ' disabled="disabled"';
}
if ($id) {
$id = ' id="' . $this->view->escape($id) . '"';
}
// XHTML or HTML end tag?
$endTag = ' />';
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
$endTag= '>';
}
// Render the button.
$xhtml = '<input type="submit"'
. ' name="' . $this->view->escape($name) . '"'
. $id
. ' value="' . $this->view->escape( $value ) . '"'
. $disabled
. $this->_htmlAttribs($attribs)
. $endTag;
return $xhtml;
}
}
So, you assign the helper to the element :
$submit = $form->createElement( 'submit', 'submitElementName' );
$submit->setAttrib( 'value', 'my value' );
$submit->helper = 'customSubmit';
$form->addELement( $submit );
This way, you can retrieve the value of the submitted form :
$form->getValue( 'submitElementName' );

zend search lucence return hit id of search insted id of field

i have poblem zend search lucence :
zend search lucence return hit id of search insted id of field.for example:
i have this codde in Yii controller for create index of news data:
public function createNewsIndex()
{
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles.'.news'), true);
$news= News::model()->findAll();
foreach ($news as $newsItem) {
$news_doc=new Zend_Search_Lucene_Document();
$news_doc->addField(Zend_Search_Lucene_Field::Text('id',CHtml::encode($newsItem->id),'utf-8'));
$news_doc->addField(Zend_Search_Lucene_Field::Text('title',CHtml::encode($newsItem->title),'utf-8'));
$news_doc->addField(Zend_Search_Lucene_Field::Text('keywords',CHtml::encode($newsItem->keywords),'utf-8'));
$index->addDocument($news_doc);
}
$index->commit();
$index->optimize();
}
i have this code for search news :
public function searchNews($term) {
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
try
{
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles . '.news'));
}
catch(Zend_Search_Lucene_Exception $e)
{
$this->createNewsIndex();
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles . '.news'));
}
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
$results = $index->find($term . '*');
$this->render('search', array(
'results' => $results,
)
}
and this code in view:
<?php foreach ($results as $result)
{
print "ID: " . $result->id . "\n";
print "Score: " . $result->title . "\n<br>";
print CHtml::link(CHtml::encode($result->title), array($controller.'/view', 'id'=>$result->id));
}
?>
i want $result->id be id of this news title but I think this is a hit ID of I think this is a test Aht ID. hit in find function according this link:(see find function)
http://phpcrossref.com/zendframework/library/Zend/Search/Lucene.php.html
.
Sorry for weak English.
i fix problem by rename id field name:
$news_doc->addField(Zend_Search_Lucene_Field::Text('news_id',CHtml::encode($newsItem->id),'utf-8'));
and in view:
<?php foreach ($results as $result)
{
print "ID: " . $result->news_id . "\n";
print "Score: " . $result->title . "\n<br>";
print CHtml::link(CHtml::encode($result->title), array($controller.'/view', 'id'=>$result->news_id));
}
?>