I have a choice menu in WordPress plug-in with ddslick . I want to pass the id of the selected option and send the form to a database , but the value is not saved although it appears within the html . When put into manual is well maintained.
<script type='text/javascript' src='http://g-page.co.il/wp-content/themes/g-page/js/jquery.ddslick.min.js'></script>
<div id="myDropdown">
<select id="demo-htmlselect">
<?php
$thumbnails = get_posts('numberposts=5');
foreach ($thumbnails as $thumbnail) {
$url = wp_get_attachment_url( get_post_thumbnail_id($thumbnail->ID) );
?>
<option value="<?php echo $thumbnail->ID;?>" data-imagesrc="<?php echo $url; ?>"
data-description="<?php echo $thumbnail->post_title;?>"><?php echo $thumbnail->post_title;?></option>
<?php } ?>
</select>
</div>
<?php
?>
<div class="wrap">
<form method="post" action="options.php">
<?php wp_nonce_field('update-options') ?>
<input type="text" name="main_art_id" size="45" value="<?php echo get_option('main_art_id'); ?>" />
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="ain_art_id" />
</form>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#myDropdown').ddslick({
onSelected: function(selectedData){
var cor_val = selectedData['selectedData']['value'];
$("input[name=main_art_id]").val(cor_val);
}
});
});
</script>
<?php
}
Related
I need to post values outside the form in php , How to do it
Here is my sample code
<input type="hidden" id="test" name="test" />
<input type="hidden" id="testvalue" name="testvalue"/>
<?Php for($i=0;$i<5;$i++) { ?>
<form action='some_url'>
<input type="text" value="dynamic_value" name='testname'>
<select name="testselect">
<option value="<?php echo $dynamicvalue[$i]?>"><?php echo $dynamicvalue[$i]?></option>
</select>
<button class="btn btn-primary book_now" type="submit">BookNow</button>
</form>
<?php } ?>
i need to post all input values above the form also,since i cannot use that input field inside the loop, i want id to be unique so i cant use inside
any other option available to post all data
Use jQuery:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
$(document).ready(function(){
$('form').submit(function(){
var test = $('#test').val();
var testvalue = $('#testvalue').val();
$(this).append('<input type="hidden" name="test" value="'+test+'">');
$(this).append('<input type="hidden" name="testvalue" value="'+testvalue+'">');
return true
});
});
</script>
You can add input fields into for-loop
<?php for($i=0;$i<5;$i++) { ?>
<form action='some_url'>
<input type="text" value="dynamic_value" name='testname'>
<select name="testselect">
<option value="<?php echo $dynamicvalue[$i]?>"><?php echo $dynamicvalue[$i]?></option>
</select>
<button class="btn btn-primary book_now" type="submit">BookNow</button>
<input type="hidden" name="test" />
<input type="hidden" name="testvalue"/>
</form>
<?php } ?>
I'm creating a web app in Codeigniter. Here's the code in VIEW's.
<div class="bold light-gray">Add a photo or two!</div>
<p class="short">Or three, or more! Prospective Buyers love photos that highlight the features of your parts or gear.</p>
<form class="ajaxform" method="post" enctype="multipart/form-data" action='<?php echo site_url('UploadImage/upload_Image');?>'>
<input type="hidden" name="do" value="upload"/>
Upload your image <input type="file" name="Filedata" id="photo" onChange="abc()" />
<input type="hidden" name="timestamp" value="<?php echo $timestamp;?>" />
<input type="hidden" name="token" value="<?php echo md5('unique_salt' . $timestamp);?>" />
<input type="hidden" name="customer_id" value="<?php echo $customer['id'];?>" />
</form>
</div>
<!-- /.box.center -->
<?php echo form_open('/secure/add_item/'.$id, array('id'=>'listitem') ); ?>
<div id="img_cant"> <?php
if(isset($images) && !empty($images)) {
foreach($images as $key=>$img){
?>
<input type="hidden" value="<?php echo $img; ?>" name="images[]" id="hid_<?php echo $key; ?>">
<?php
}
}
?>
</div>
I want to allow the user to just add 3 or 4 images maximum. How to do that?
<?php $count=count($_FILES['name']);
if($count>3)
{
echo "Your error message";
}
else{
echo "your desired activity";
}?>
Using jquery you can call this function while submit your form
var file_nu = $("input:file")[0].files.length;
if(file_nu >3)//apply your condition here
{
return FALSE;
}else{
return TRUE;
}
I'm making a To do application in PHP for a school assignment.
At this point, I can add new tasks. But the problem is:
When I click at a div (to delete it), the div is deleted, BUT all the other tasks get invisible. They only show up again if I create a new task.
This is my code
File Index.php
<div class="container">
<form action="/Periodeopdracht/index.php" method="POST">
<div class="headerToDo">
<input class="addText title" type="text" value="Click to add a task" name="nextToDo">
<input class="clickablePlus" type="submit" value="+" name="submit"></div>
</form>
<?php if(!$empty): ?>
<?php foreach ($_SESSION["todoList"] as $_SESSION["key"] => $toDo): ?>
<div class="toDo">
<form action="/Periodeopdracht/index.php" method="POST">
<button value="<?php echo $_SESSION["key"] ?>" name="delete" class="delete" type="submit" >X</button>
<button value="<?php echo $_SESSION["key"] ?>" name="done" class="done" type="submit" >V</button>
<div value="<?php echo $_SESSION["key"] ?>" class="textToDo"><?= $toDo ?></div>
</form>
</div>
<?php endforeach ?>
<?php endif ?>
</div>
Application.php
<?php
session_start();
$GLOBALS["empty"] = true;
$_SESSION['todoList'] = isset($_SESSION['todoList']) ? $_SESSION['todoList'] : array();
if(isset($_POST["submit"]))
{
$empty = false;
array_unshift($_SESSION['todoList'], $_POST["nextToDo"]);
}
if(isset($_POST["delete"]))
{
unset($_SESSION['todoList'][$_SESSION["key"]]);
//var_dump($key);
}
?>
Try to handle it like a normal post, since this key will be available on submission:
<!-- no need to create every form -->
<form action="/Periodeopdracht/index.php" method="POST">
<?php foreach ($_SESSION["todoList"] as $key => $toDo): ?>
<div class="toDo">
<button value="<?php echo $key; ?>" name="delete" class="delete" type="submit" >X</button>
<button value="<?php echo $key; ?>" name="done" class="done" type="submit" >V</button>
<div value="<?php echo $key; ?>" class="textToDo"><?= $toDo ?></div>
</div>
<?php endforeach; ?>
</form>
Then, upon submission:
if(isset($_POST["delete"])) {
$key = $_POST["delete"];
unset($_SESSION['todoList'][$key]);
}
Sidenote: Are you sure your form action is /Periodeopdracht/index.php? Maybe this operation is intended to use Application.php like you posted the $_POST processes above.
Also, this is superfluous/unneeded.
$_SESSION['todoList'] = isset($_SESSION['todoList']) ? $_SESSION['todoList'] : array();
This reassignment makes no sense.
Just use a simple initialization:
if(!isset($_SESSION['todoList'])) {
$_SESSION['todoList'] = array();
}
A Little bit of rewrite:
Form:
<div class="container">
<form action="/Periodeopdracht/index.php" method="POST">
<div class="headerToDo">
<input class="addText title" type="text" value="Click to add a task" name="nextToDo">
<input class="clickablePlus" type="submit" value="+" name="submit"></div>
</form>
<!-- no need to create every form -->
<form action="/Periodeopdracht/index.php" method="POST">
<?php foreach($_SESSION["todoList"] as $key => $toDo): ?>
<div class="toDo">
<button value="<?php echo $key; ?>" name="delete" class="delete" type="submit" >X</button>
<button value="<?php echo $key; ?>" name="done" class="done" type="submit" >V</button>
<div class="textToDo"><?php echo $toDo; ?></div>
</div>
<?php endforeach; ?>
</form>
</div>
Then in /Periodeopdracht/index.php:
<?php
session_start();
// simple initialization
if(!isset($_SESSION['todoList'])) {
$_SESSION['todoList'] = array();
}
// addition / push inside items
if(isset($_POST["submit"], $_POST["nextToDo"])) {
$_SESSION['todoList'][] = $_POST["nextToDo"];
}
// delete key
if(isset($_POST["delete"])) {
$key = $_POST["delete"];
unset($_SESSION['todoList'][$key]);
}
?>
I'm building my first WP plugin. Basically I should upload a CSV file and then read it values to store in a table at Wordpress DB. After read a lot of docs I follow this steps:
Create two files frequent-traveler.php where all the logic resides and ft_admin.php where the view part is.
This is the code I have in frequent-traveler.php:
// Create database tables and some others
function frequent_traveler_activation()
{
}
register_activation_hook(__FILE__, 'frequent_traveler_activation');
// Deletes database tables and some others
function frequent_traveler_deactivation()
{
}
register_deactivation_hook(__FILE__, 'frequent_traveler_deactivation');
function frequent_traveler_admin_actions()
{
add_options_page("Frequent Traveler Configuration", "Frequent Traveler Config", 'manage_options', "ftconfig", "frequent_traveler_admin");
}
add_action('admin_menu', 'frequent_traveler_admin_actions');
function frequent_traveler_admin()
{
include('ft_admin.php');
}
if (!empty($_POST) && isset($_POST['uploadfile_btn']) && check_admin_referer('name_of_my_action', 'wpnf_ft')) {
echo "entre";
}
else {
echo "Error";
}
And this is the code at ft_admin.php:
<?php
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
?>
<div class="wrap">
<?php echo "<h2>" . __('Frequent Traveler Configuration') . "</h2>"; ?>
<form name="frequent_traveler_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="frequent_traveler_hidden" value="Y">
<?php echo "<h4>" . __('Common Settings') . "</h4>"; ?>
<p>
<?php _e("Default Conversion Value: "); ?><input type="text" name="ft_default" value="<?php echo $ft_default; ?>" size="5">
<?php _e("From Date: "); ?><input type="text" id="frequent_traveler_from_date" name="frequent_traveler_from_date" value="<?php echo $frequent_traveler_from_date ?>" class="datepicker" />
<?php _e("To Date: "); ?><input type="text" id="frequent_traveler_to_date" name="frequent_traveler_to_date" value="<?php echo $frequent_traveler_to_date; ?>" class="datepicker" />
</p>
<input type="submit" class="button-primary" name="Submit" value="<?php _e('Save Values') ?>" />
</form>
<hr/>
<?php ?>
<h2><?php echo __('Upload file to import') ?></h2>
<form name="uploadfile" id="uploadfile_form" method="POST" enctype="multipart/form-data" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']) . '/uploadfile'; ?>" accept-charset="utf-8" >
<?php wp_nonce_field('name_of_my_action', 'wpnf_ft'); ?>
<p><?php echo __('Select file to upload') ?><input type="file" name="uploadfiles[]" id="uploadfiles" size="35" class="uploadfiles" /><p>
<input class="button-primary" type="submit" name="uploadfile_btn" id="uploadfile_btn" value="<?php echo __('Upload & Process') ?>" />
</form>
</div>
<script>
jQuery(document).ready(function() {
jQuery('.datepicker').datepicker({
dateFormat: 'dd/mm/yy'
});
});
</script>
As you may notice I'm trying to validate the uploaded file with this code:
if (!empty($_POST) && isset($_POST['uploadfile_btn']) && check_admin_referer('name_of_my_action', 'wpnf_ft')) {
echo "entre";
}
else {
echo "Error";
}
But I get always Error, why is that? What I'm doing wrong? Which is the best way to handle uploaded files?
You should not leave the check for if (!empty($_POST) outside any function, it can go inside the admin_menu output.
Also, the form actions should be left empty, so it posts to the same plugin page.
The targeted enqueue can be done in a standard way too and note the shortcut for jQuery $:
add_action( 'admin_menu', 'frequent_traveler_admin_actions' );
add_action( 'admin_enqueue_scripts', 'admin_enqueue' );
function frequent_traveler_admin_actions()
{
$my_hook = add_options_page("Frequent Traveler Configuration", "Frequent Traveler Config", 'manage_options', "ftconfig", "frequent_traveler_admin");
//var_dump($my_hook); die();
}
function admin_enqueue( $hook )
{
if( 'settings_page_ftconfig' !== $hook )
return;
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
}
function frequent_traveler_admin()
{
if (!empty($_POST) && isset($_POST['uploadfile_btn']) && check_admin_referer('name_of_my_action', 'wpnf_ft')) {
echo "<h1>entre</h1>";
}
else {
echo "<h1>Error</h1>";
}
$ft_default = '';
$frequent_traveler_from_date = '';
$frequent_traveler_to_date = '';
?>
<div class="wrap">
<?php echo "<h2>" . __('Frequent Traveler Configuration') . "</h2>"; ?>
<form name="frequent_traveler_form" method="post" action="">
<input type="hidden" name="frequent_traveler_hidden" value="Y">
<?php echo "<h4>" . __('Common Settings') . "</h4>"; ?>
<p>
<?php _e("Default Conversion Value: "); ?><input type="text" name="ft_default" value="<?php echo $ft_default; ?>" size="5">
<?php _e("From Date: "); ?><input type="text" id="frequent_traveler_from_date" name="frequent_traveler_from_date" value="<?php echo $frequent_traveler_from_date ?>" class="datepicker" />
<?php _e("To Date: "); ?><input type="text" id="frequent_traveler_to_date" name="frequent_traveler_to_date" value="<?php echo $frequent_traveler_to_date; ?>" class="datepicker" />
</p>
<input type="submit" class="button-primary" name="Submit" value="<?php _e('Save Values') ?>" />
</form>
<hr/>
<?php ?>
<h2><?php echo __('Upload file to import') ?></h2>
<form name="uploadfile" id="uploadfile_form" method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8" >
<?php wp_nonce_field('name_of_my_action', 'wpnf_ft'); ?>
<p><?php echo __('Select file to upload') ?><input type="file" name="uploadfiles[]" id="uploadfiles" size="35" class="uploadfiles" /><p>
<input class="button-primary" type="submit" name="uploadfile_btn" id="uploadfile_btn" value="<?php echo __('Upload & Process') ?>" />
</form>
</div>
<script>
jQuery(document).ready(function($) {
$('.datepicker').datepicker({
dateFormat: 'dd/mm/yy'
});
});
</script>
<?php
}
Evry time while logging in an error "INVALID TOKEN" its shown at the joomla2.5/jomsocial2.4 site, but after 2,3 refreshes it shows the profile page as logged in... why is it so.... Is it problem of Joomla... I have uninstalled a plugin alphauserpoints ... is that a problem.. or should i modify the code default.php
<?php
// no direct access
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
?>
<?php if ($type == 'logout') : ?>
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form">
<?php if ($params->get('greeting')) : ?>
<div class="login-greeting">
<?php if($params->get('name') == 0) : {
echo JText::sprintf('MOD_LOGIN_HINAME', $user->get('name'));
} else : {
echo JText::sprintf('MOD_LOGIN_HINAME', $user->get('username'));
} endif; ?>
</div>
<?php endif; ?>
<div class="logout-button">
<input type="submit" name="Submit" class="button" value="<?php echo JText::_('JLOGOUT'); ?>" />
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.logout" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
<?php else : ?>
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form" >
<?php if ($params->get('pretext')): ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
</div>
<?php endif; ?>
<fieldset class="userdata">
<p id="form-login-username">
<label for="modlgn-username"><?php echo JText::_('MOD_LOGIN_VALUE_USERNAME') ?></label>
<input id="modlgn-username" type="text" name="username" class="inputbox" size="18" />
</p>
<p id="form-login-password">
<label for="modlgn-passwd"><?php echo JText::_('JGLOBAL_PASSWORD') ?></label>
<input id="modlgn-passwd" type="password" name="password" class="inputbox" size="18" />
</p>
<?php if (JPluginHelper::isEnabled('system', 'remember')) : ?>
<p id="form-login-remember">
<label for="modlgn-remember"><?php echo JText::_('MOD_LOGIN_REMEMBER_ME') ?></label>
<input id="modlgn-remember" type="checkbox" name="remember" class="inputbox" value="yes"/>
</p>
<?php endif; ?>
<input type="submit" name="Submit" class="button" value="<?php echo JText::_('JLOGIN') ?>" />
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
<ul>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=reset'); ?>">
<?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_PASSWORD'); ?></a>
</li>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=remind'); ?>">
<?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_USERNAME'); ?></a>
</li>
<?php
$usersConfig = JComponentHelper::getParams('com_users');
if ($usersConfig->get('allowUserRegistration')) : ?>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=registration'); ?>">
<?php echo JText::_('MOD_LOGIN_REGISTER'); ?></a>
</li>
<?php endif; ?>
</ul>
<?php if ($params->get('posttext')): ?>
<div class="posttext">
<p><?php echo $params->get('posttext'); ?></p>
</div>
<?php endif; ?>
or does the uninstallation affected the configuration file of joomla
Try this link: http://developersbench.in/invalid-token-during-registration-jomsocial/#.T19wtHm45F0 . You might get some help from this.
The info i have about this is every time you open a page and submit a form it first validates the token and if token is expired which is mainly because of remaining idle on the page for a few time, then you get "Invalid token" error.
Simply if you are not worried about the token, go to the file root/libraries/joomla/environment/request.php and check the below function
function checkToken( $method = 'post' ), comment all the lines between this and simply return true, whatever be the case. I haven't tried this, but i guess this will work.