I Put the Database Search for my Plugin.
But When Searching gives 404 Error !
What do I do to fix 404 Error?
My Code is:
<?php
function qrn_search_code(){
global $wpdb,$table_prefix;
if($_POST['submit']) {
if($_POST['search']) {
$search = $wpdb->get_results("SELECT ID, code FROM ".$table_prefix."qrn_dessini WHERE code LIKE '%".$_POST['search']."%' ORDER BY ID DESC;");
print_r($search);
}
}
<form method="POST" id="searchform">
<input type="text" name="name" class="qr_search" placeholder="جستجوی کد محصول ...">
<input type="submit" name="submit" value="Search" class="qr_submit">
</form>
}
add_shortcode('search_code','qrn_search_code');
?>
Thanks
I notice you have a beginning php tag at the end of your function, and also no ending:
<?php
}
add_shortcode('mysearch','search_code');
So I would try to change this to start:
}
<?php
add_shortcode('mysearch','search_code');
?>
Related
Here is my code for file uploading in PHP. All the things seems at place but file is not getting added into the selected folder. The destination folder is stored in the same folder, where .php file is stored. Please help !!!
<form action="" method="post" enctype="multipart/form-data">
Select Image File to Upload:
<p><input type="file" name="file"/></p>
<p><input type="submit" name="upload" value="Upload"/></p>
</form>
I will take the same example
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
in your case you are missing attribute value of action
File : upload.php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
I have also share the link with you were you can use different type of validation on file uploads
https://www.w3schools.com/php/php_file_upload.asp
i have made this simple app with gmaps.js but i need the search functions like they show it here:
http://hpneo.github.io/gmaps/examples/geocoding.html
i looked at the source code and all but it aint working.. The search button reloads the page...
my code is a follows:
<script>
$('#geocoding_form').submit(function(e){
e.preventDefault();
GMaps.geocode({
address: $('#address').val().trim(),
callback: function(results, status){
if(status=='OK'){
var latlng = results[0].geometry.location;
map.setCenter(latlng.lat(), latlng.lng());
}
}
});
});
</script>
<form method="post" id="geocoding_form">
<label for="address">Address:</label>
<div class="input">
<input type="text" id="address" name="address" />
<input type="submit" class="btn" value="Search" />
</div>
</form>
<div id="map"></div>
the rest is loaded in from scripts.js you can see it in sourcecode. Why is this happening and how can i fix this?
The web app is located here, http://travelers.work/trein/
You need to change
map.setCenter(latlng.lat(), latlng.lng());
to
map.setCenter(latlng);
because the search returns a LatLng object as a result, and that's what is needed as an input for setCenter.
Here's a JS demo with your code: http://jsfiddle.net/DuRhR/3/
EDIT after comments:
Alternatively, you can pass to setCenter a LatLngLiteral
map.setCenter({lat: latlng.lat(), lng: latlng.lng()});
I am developing a plugin, where I am using bootstrap nav tabs function to display different forms on selecting menu . I want to use nonce function . Should I give seperate nonce function for every form or same nonce for all the forms as they are on the same page. Pls guide.?
Each form should have its own nonce, even those forms are on the same page.
If the form is present in admin pages then we should use check_admin_referer function to verify the nonce.
example:
<html>
<div>
<form id="form1"method="post" action="">
<input type="text" name="something" value=""/>
<?php wp_nonce_field('some_form','some_form_nonce');?>
<input type ="hidden" name="form_name" value ="1"/>
<input type="submit" name="submit"/>
</div>
<div>
<form id="form2"method="post" action="">
<input type="text" name="someother" value=""/>
<?php wp_nonce_field('some_other','some_other_nonce');?>
<input type ="hidden" name="form_name" value ="2"/>
<input type="submit" name="submit"/>
</div>
</html>
after that on processing page you should add the code like this
<?php
if(!isset($_POST['form_name'])){
if($_POST['form_name']==1){
if ( ! empty( $_POST ) && check_admin_referer( 'some_form', 'some_form_nonce' ) ) {
// process form1 data
}else if($_POST['form_name']=2){
if ( ! empty( $_POST ) && check_admin_referer( 'some_other', 'some_other_nonce' ) ) {
// process form2 data
}
}
?>
This code I tried in my app and is working as I expected...
I'm developing a magento store and in the product view page/details page i have added a jquery quantity box.It works fine.But when click on the add to cart button always add "1" to the cart although i changed the quantity amount in the quantity box.I searched this issue in every place possible sites.But still no luck.And i have placed the input quantity box at the correct place.That means inside the form.I can't figure it out the issue.Hope a help.And my Magento version is 1.8.
This works with form tag... you can edit your default/theme/template/catalog/product/view/addtocart.phtml like this.
<form>
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<label class="qty_label" for="qty"><?php echo $this->__('Quantity') ?>:</label>
<div class="qty_pan">
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
<?php endif; ?>
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<?php endif; ?>
</form>
From Magento version 1.8 onwards, you need to add formkey value inside your form.
If formkey is not set in the form, then always the default qty 1 will be added to cart.
Also, if you try to update the qty from cart page, it will not get updated and will always be set to 1.
To solve this issue, add the following code inside the <form > tag:
<?php echo $this->getBlockHtml('formkey'); ?>
This code is similar to:
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
Porduct View Page
app/design/frontend/YOUR_PACKAGE/YOUR_THEME/catalog/product/view.phtml
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
<?php echo $this->getBlockHtml('formkey'); ?>
Shopping Cart Page
app/design/frontend/YOUR_PACKAGE/YOUR_THEME/checkout/cart.phtml
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<?php echo $this->getBlockHtml('formkey'); ?>
I need to redirect page into external site with POST parameters, but I cannot use vanilla HTML <form action="url"> like it is explained here:
JSF commandButton - passing POST params to an external site
because then the form would be within a jsf form - and it doesn't work.
Is it possible to use:
FacesContext.getCurrentInstance().getExternalContext().redirect("http://example.com");
with POST parameters without additional vanilla form somehow? Or maybe there is other way to acheive this without form?
Try something like this:
JAVASCRIPT:
function redirect() {
document.getElementById("mySubmitButton").submit();
}
XHTML:
<h:form>
<span onclick="javascript:redirect()" class="linkClass">REDIRECT</span>
</h:form>
<div style="display:none:"> <!-- If you want it hidden -->
<form action="http://external/myplace.html" method="post">
<input type="hidden" value="value1"></input>
<input type="submit" id="mySubmitButton"</input>
</form>
</div>
EDIT: Added another test.
PASSING DYNAMIC PARAMETER:
In this example we assume that we are always going to send a value.
JAVASCRIPT:
function redirect(dynamicValue) {
document.getElementById("dynamicField").value = dynamicValue;
document.getElementById("mySubmitButton").submit();
}
XHTML:
<h:form>
<span onclick="javascript:redirect('myValue')" class="linkClass">REDIRECT</span>
</h:form>
<div style="display:none:"> <!-- If you want it hidden -->
<form action="http://external/myplace.html" method="post">
<input id="dynamicField" type="hidden" value=""></input>
<input type="hidden" value="value1"></input>
<input type="submit" id="mySubmitButton"</input>
</form>
</div>