Wordpress post form goes to 404 page - wordpress

I'm coding a plugin that requires forms but I'm having some troubles on post sends.
I had read that the fields names can be a problem for this... But I have 3 fields: cmbParkings, cmbTarifas and dpkFechaEntrada.
My plugin register one custom post type called parking-parkia and one taxonomy for this post type with Ciudades as name.
I don't see where the problem can be! Maybe the field values could be a problem?
Explaination of fields:
cmbParkings is a select filled with all my custom posts (value=id, text=title).
cmbTarifas is dependant from cmbParkings, it loads a metadata from the parking-parkia previously selected (by the moment, value and text = metadata value, containing any characters)
dpkFechaEntrada is a date input.
If I do print_r($_POST) on my 404 page, I see my 404 loaded with the correct values from my form in the $_POST variable.
EDIT: I had comment all fields in form and 404 page still appearing on submit.
Form without fields:
<form id="frmFormularioBusqueda" method="post" action="http://mutuaparkia.extrasoft.es/?p=2632">
<div div="divBotonReserva">
<button type="submit" id="btnEnvioParking">Reservar</button>
</div>
</form>
Form with fields:
<form id="frmFormularioBusqueda" method="post" action="http://mutuaparkia.extrasoft.es/?p=2632">
<div id="selectorParking">
<select id="cmbParkings" name="msolla-cmbParkings">
<option value="0">Elige Parking</option>
<option value="2632">Parking Goya</option>
<option value="2633">Parking Córdoba</option>
<option value="2631">Parking Montalbán</option>
</select>
</div>
<div id="divSelectorTarifa">
<select id="cmbTarifas" name="msolla-cmbTarifas">
<option value="0">Elige Tarifa</option>
</select>
</div>
<div id="divSelectorFecha">
<input id="dpkFechaEntrada" name="msolla-dpkFechaEntrada" type="date">
</div>
<div div="divBotonReserva">
<button type="submit" id="btnEnvioParking">Reservar</button>
</div>
Note: the action url exists and it is ok.
Js that change the action form when the first select is changed:
$( document ).ready(function() {
$("#cmbParkings").change(function(){
//http://mutuaparkia.extrasoft.es/?p=2632
if($.isNumeric($("#cmbParkings").val())){
//$("#frmFormularioBusqueda").attr('action', '/?p=' + $("#cmbParkings").val());
$("#frmFormularioBusqueda").attr('action', $("#txtPermalink" + $("#cmbParkings").val()).val());
}
else{
$("#frmFormularioBusqueda").removeAttr( "action" )
}
$("#cmbTarifas").html($("#cmbTarifas" + $("#cmbParkings").val() ).html());
});
});
Edit: inside if, there is a commented line that it was bad. The new line is working fine now.

Thanks to vard, he had seen that changing the action from from url/?p=id
to the custom post permalink, the code works.

Related

How to make the data show by filter in a razor page?

The part of the view where I filter it through Car Categories:
<div class="form-group">
<select class="form-control" id="sel1">
<option value="" disabled selected hidden>Car Styles</option>
#foreach (var item in Model.CarCats)
{
<option value="#item.CarCategoryID">#item.CarCategoryName</option>
}
</select>
</div>
The part of the view where I have cars:
#foreach (var item in Model.Cars)
{
<div class="col-lg-4">
<div class="carGalleryWrapper">
<div class="carGallery" style="background:url('#Html.DisplayFor(modelItem=>item.ImagePath)') no-repeat 0 0 ">
<div class="carDetails">
<h4>#Html.DisplayFor(modelItem => item.DailyFee) / Per Day</h4>
<h3>#Html.DisplayFor(modelItem => item.Make) #Html.DisplayFor(modelItem => item.Model), Navi, Leather, ABS</h3>
<button type="submit" class="driveMore">
#Html.ActionLink("Drive Now", "Detail", null, new { id = item.CarID }, htmlAttributes: new {})</button>
</div>
</div>
</div>
</div>
}
I want to show the cars of a category when i select it from the dropdown.
Theres a few ways of going about this
Use a form and populate a new Car list serverside (server side)
submit the form with the selected category, in your method for handling your form
remove cars from your list that dont have that category etc.
A good example of this is here
In the method that takes your page model(the method that will be posted to on form submission) that is where you would filter your car list down by category. Then return the same page.
This doesnt use js so it will always work even if your user has disabled js in their browser however its not the most user friendly due to the page reloading.
Use js to call an api that takes in a category and returns a new list of cars (client and server side)
Then repopulate your frontend with the new list
My js isnt by any stretch any good but the rough idea is to create an api controller that will take in your category and return the filtered list.
look at this answer for a start here if you look at the success response of the ajax call, it builds up html and thats what you would need to do with the filtered list returned from the api
Use js and css to hide/show cars based on the selected category (client side)
Did you have a preference?

Silverstripe 4 - How do you enable FullTextSearchable and $SearchForm?

Upgrading site from 3 to 4. Existing code makes use of FullTextSearchable as per this guide that exists for 3, but not for 4. Google only results in unanswered questions of the same nature. Except for this one, which doesn't help. But I do find this guide for SS4, which is not geared towards the same topic really, but somewhat helpful.
Here is my code:
_config.php
\SilverStripe\ORM\Search\FulltextSearchable::enable();
Page.php
use SilverStripe\ORM\Connect\MySQLSchemaManager;
private static $create_table_options = [
MySQLSchemaManager::ID => 'ENGINE=MyISAM'
];
Page.ss
$SearchForm
Expected: Standard search form is displayed
Actual: Nothing is displayed
I went as far as to hard code the form from the existing site onto the template to see if the search function itself works:
Page.ss
<form id="SearchForm_SearchForm" action="/home/SearchForm" method="get" enctype="application/x-www-form-urlencoded">
<p id="SearchForm_SearchForm_error" class="message " style="display: none"></p>
<fieldset>
<input type="text" name="Search" value="Search" class="text nolabel" id="SearchForm_SearchForm_Search">
<div class="form-group">
<input type="submit" name="action_results" value="Go" class="action" id="SearchForm_SearchForm_action_results">
</div>
</fieldset>
</form>
Expected: Search results page displays with relevant search results for the entered term
Actual: 404 page not found

how to define a select component within a clr-tab

Tried to insert a "select" component under a tab. Basically, the tab just displays some dynamic forms. The select is a list of string for user selection Looks like my definition is correct. Do not know why it messed up the whole angular/clarity UI page.
<clr-tab>
<button clrTabLink>Submission Form</button>
<clr-tab-content>
<br>
<label class="required" for="uniqueCertIDs">Unique Cert IDs</label>
<div class="select">
<select id="partnercertIDs" formControlName="EEPortalProductDetails">
<option *ngFor="let ucertID of uniquecertIDs" [value]="ucertID.UniqueCertId">{{ucertID.UniqueCertId}} </option>
</select>
</div>
Very likely, the scope of the select portion is not correct. Failed finding related documentation.
It's difficult to say whats happening without a running example.
I created a simple form with a select in a tab and it seems to be ok.
Here is the template code for my tabs:
<clr-tabs>
<clr-tab>
<button clrTabLink id="link1">Tab1</button>
<clr-tab-content id="content1" *clrIfActive>
<h3>Form 1</h3>
<form>
<div class="form-group">
<label for="selects_1">This is a select box</label>
<div class="select">
<select id="selects_1">
<option>Select</option>
<option *ngFor="let user of users" [value]="user">{{user}} </option>
</select>
</div>
</div>
</form>
</clr-tab-content>
</clr-tab>
</clr-tabs>
You can see this running here: https://stackblitz.com/edit/so-tabs-form-select
If this doesn't solve your issue, can you fork the StackBlitz and recreate it there?
<form [formGroup]="partnersForm" >
<div class="form-group">
<label class="required" for="selects_1">Unique Cert IDs</label>
<div class="select" >
<select id="selects_1" formControlName="partnerFormCertIDs" ng-change="selectAction()">
<option *ngFor="let ucertID of uniquecertIDs" [value]="ucertID.UniqueCertId" >{{ucertID.UniqueCertId}}</option>
</select>
</div>
</div>
</form>
and in my Session.ts file. Debug using console, the alert never shows up
selectAction() {
alert("selected value changed !!!!");
}
#nextgen-ui Regarding your second issue, the data binding syntax should be either on-change or (change); ng-change is an AngularJS directive.
Please see this Stackblitz.
#Jose Gomes
The event is defined as updateCertData()
<form [formGroup]="partnersForm" >
<div class="form-group">
<label class="required" for="selects_1">Unique Cert IDs</label>
<div class="select">
<select id="selects_1" formControlName="partnerFormCertIDs" (change)="updateCertData()">
<option *ngFor="let ucertID of uniquecertIDs" [value]="ucertID.UniqueCertId">{{ucertID.UniqueCertId}}</option>
</select>
</div>
</div>
</form>
And I defined a POST API in the event
updateCertData(){
let selectedCertID = this.partnersForm.get('partnerFormCertIDs').value;
for ( let partnerInfo of this.uniquecertIDs) {
if(partnerInfo.UniqueCertId == selectedCertID){
this.extractSubmit(this.cert);
this.submit[0].Option[0].value = partnerInfo.ProductId;
this.submit[0].Option[1].value = partnerInfo.ProductName;
this.certsService.setSubmissionProduct(this.certId, this.submit);
break;
}
}
}
this.certsService.setSubmissionProduct is a POST API, sending data back to UI Server
setSubmissionProduct(sessionId: string, info:any){
let body = {'submitConfig': info};
let url = GLOBALS.baseUrl + "session/" + sessionId + "/submitproduct";
return this.post(url, body);
}
The this.post never sends message to the controller successfully. I tried several other post methods, which works well in other logic part, but never sends message successfully if it is put within this "change" event.

ASP.NET MVC: Click on a button to redirect based on drop down list's value

Can anyone help me on how to create a drop down list to redirect in ASP.NET?
When click on the "Create" button, the current view should be redirected to different views based on the drop down list's value.
For example, when I select on "1" from the list then click on the Create button, it should do something like: Response.Redirect("~/Drama/Create");
My drop down list code is:
<div class="jumbotron">
<form action="/Home" method="get">
<fieldset>
Movie Type: <select id="MovieType" name="MovieType">
<option value="Action">0</option>
<option value="Drama">1</option>
<option selected="selected" value="Comedy">2</option>
<option value="Science Fiction">3</option>
</select>
<p><input type="submit" value="Submit" /> </p>
</fieldset>
</form>
</div>
Listen to the form submit event /button click of the submit button and read the selected option value and build the url and do a redirect
$(function(){
$("form").submit(function(e){
e.preventDefault(); // prevent default form submit behaviour
var selectedItem = $("#MovieType").val();
var url = "#Url.Content("~")"+selectedItem + "/create";
alert(url);
window.location.href=url;
})
})

Wordpress : Adding meta box in Admin Menu page

I am working on a plugin, which creates a couple of Virtual pages, and I wish these links to be available in Menu admin page, to let users have the liberty to add them as they create menus.
I want to add a Meta box in Menu administration, very similar to Page/Category meta boxes, to let users select what page to add in their menu.
Apparently, the only possible research is in the core itself.
Here, /wp-includes/nav-menu.php, we can get how to insert the meta box:
add_action('admin_init', 'so_13875144_nav_menu_meta_box');
function so_13875144_nav_menu_meta_box() {
add_meta_box(
'my-custom-nav-box',
__('Custom Box'),
'so_13875144_display_menu_custom_box',
'nav-menus',
'side',
'default'
);
}
function so_13875144_display_menu_custom_box() {
/* Not sure about this global var */
//global $_nav_menu_placeholder;
//$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
?>
<p id="menu-item-custom-box">
<label class="howto" for="custom-menu-item-custom-box">
<span><?php _e('URL'); ?></span>
<input id="custom-menu-item-custom-box" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-custom-box]" type="text" class="code menu-item-textbox" value="my text" />
</label>
</p>
<?php
}
But, the hard part, which I haven't managed to make work, is to save the value.
This is the file /wp-admin/nav-menus.php that has to be studied.
Tried to hook into the action wp_update_nav_menu, but the custom meta box input field is not being passed into $_POST.
WordPress Answers may have some hint: https://wordpress.stackexchange.com/search?q=wp_update_nav_menu
http://codex.wordpress.org/Function_Reference/add_meta_box
Use the post_type 'nav-menus'
I know I'm late to the party but just for anyone else trying to do this...
b__ is right, that is the way to get it to show on the page except it is much easier to use checkboxes than any other field because there is an inbuilt javascript function that looks for checkboxes.
All you need to do is copy the html from an existing checkbox -
<li><label class="menu-item-title"><input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="2"> Sample Page</label><input type="hidden" class="menu-item-db-id" name="menu-item[-1][menu-item-db-id]" value="0"><input type="hidden" class="menu-item-object" name="menu-item[-1][menu-item-object]" value="page"><input type="hidden" class="menu-item-parent-id" name="menu-item[-1][menu-item-parent-id]" value="0"><input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="post_type"><input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="Sample Page"><input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value=""><input type="hidden" class="menu-item-target" name="menu-item[-1][menu-item-target]" value=""><input type="hidden" class="menu-item-attr_title" name="menu-item[-1][menu-item-attr_title]" value=""><input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" value=""><input type="hidden" class="menu-item-xfn" name="menu-item[-1][menu-item-xfn]" value=""></li>
but give them each a unique ID and put your details in for the URL, title etc.
Then, add a submit button at the end to add to the menu -
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="YOUR NAME" id="YOUR ID" onclick="(function(){$('#THE DIV YOU HAVE PUT YOUR LIST IN').addSelectedToMenu( api.addMenuItemToBottom );})"/>
And that should add the item to the list.
This is a pretty old question but I was trying to do this today so in case it points anyone in the right direction...
I won't cover adding the meta box, as it's covered above. I'll also only cover a custom link as I haven't looked into adding a post, page, term link etc.
Just to cover the logic of how I got there...Looking at wp-admin/js/nav-menu.js, for a custom link you'll want to use window.wpNavMenu.addItemToMenu(). This ajax submits to the function wp_ajax_add_menu_item() in wp-admin/includes/ajax-actions.php. This then submits to wp_save_nav_menu_items() in wp-admin/includes/nav-menu.php. The upshot from looking at these files is that all menu items are of a post_type, taxonomy, post_type_archive or custom type.
Hook the javascript to the HTML as you wish, but if you want to submit a custom link, you need to call addItemToMenu() as follows:
var url = 'http://example.com';
var title = 'Link text';
window.wpNavMenu.addItemToMenu({
'-1': {
'menu-item-type': 'custom',
'menu-item-url': url,
'menu-item-title': title,
}
}, window.wpNavMenu.addMenuItemToBottom);
Menu item type has to be "custom" otherwise it requires info for a post, page etc. with which to associate the menu item.

Resources