I have this code:
if('open' == $post->comment_status || !isset($_GET['wp_accept_favor']))
{
// show comment form
}
else
{
// dont show comment form
}
domain.com/?wp_accept_favor then show comment form
domain.com/?wp_accept_favor=2 then dont show comment form
How do I do that? Thanks
if('open' == $post->comment_status ||
(isset($_GET['wp_accept_favor']) && empty($_GET['wp_accept_favor'])) )
{
// show comment form
}
else if(isset($_GET['wp_accept_favor']) && !empty($_GET['wp_accept_favor']))
{
// do not show comment form
}
Related
I have a form in PHP and if user put correct coupon code something like that is defined:
$ret['status'] = 'success';
and next is:
if( $ret['status'] == 'success' ){
$ret['coupon-id'] = $query->post_id;
$ret['amount'] = $post_option['coupon-discount-amount'];
$ret['type'] = $post_option['coupon-discount-type'];
$discount_text = '';
if( $ret['type'] == 'percent' ){
$discount_text = $post_option['coupon-discount-amount'] . '%';
}else{
$discount_text = gdlr_lms_money_format($post_option['coupon-discount-amount']);
}
$ret['message'] = sprintf(__('You got %s discount', 'gdlr-lms'), $discount_text);
}
And the bottom of the form there is submit button with this conditions:
if( empty($_POST['first_name']) || empty($_POST['last_name']) || empty($_POST['email']) ){
$ret['status'] = 'failed';
$ret['message'] = __('Please fill all required fields.', 'gdlr-lms');
I need to add to this condition that correct coupon is also required. What I need to add to this code to have it done? I have been looking for answers for 5 hours and I tried everything what I have found but nothing work - please help me! :)
This is the website with form - after registration form there will be the entry form to the course I am ask about.
http://semcamp.university/course/starting-company-all-you-need-to-know-to-start-company-2-2-2-2/
You can login in using username: stackoverflow and password: stack1 and valid copuon code is 1234 or test1
Your question is not very clear about in which if statement should the coupon be validated. But, supposing that it needs to be validated in the last one (the if for the submit button), you could do it that way:
if( empty($_POST['first_name']) || empty($_POST['last_name']) || empty($_POST['email']) ){
$ret['status'] = 'failed';
$ret['message'] = __('Please fill all required fields.', 'gdlr-lms');
}
elseif( $ret['status'] != 'success') {
$ret['status'] = 'failed';
$ret['message'] = __('Please provide a valid coupon.', 'gdlr-lms');
}
I have a simple form that I'm trying to add a checkbox to, I have everything on the form setup correctly but when I try to handle the check box I'm only able to make echos work. I'm trying set whether the box is checked as a yes or no and store that yes/no in a variable, here is what I have in my handle form for the checkbox:
if(isset($_POST['race']) &&
$_POST['race'] == 'Yes')
{
$race1 == "yes";
}
else
{
$race1 == "No";
}
You need to use the single equal sign when assigning values. Double equals does a comparison.
if(isset($_POST['race']) && $_POST['race'] == 'Yes')
{
$race1 = "yes";
}
else
{
$race1 = "No";
}
== is a comparison operator. You need to use attribution operator =
if (isset($_POST['race']) &&
strtolower($_POST['race']) == 'yes')
{
$race1 = 'yes';
}
else
{
$race1 = 'No';
}
I am learning how to code PHP and I have two pages: rates.html and rates.php. Our assignment has it so that we only need to run rates.php and will no longer need to use rates.html. My way of going around this problem is as follows:
if (empty($_POST['txtInput'])){
$inputCurrency = 0;
$outputCurrency = 0;
$txtInput = '';
} else {
$inputCurrency = $_POST['inputCurrency'];
$outputCurrency = $_POST['outputCurrency'];
$txtInput = $_POST['txtInput'];
}
Input and output currencies are made in the form of a drop down list, and txtInput is the number that the user wants to convert.
The only problem with this is that my page throws up an error message when a user submits a form without any input in the field. The page loads the following code:
if ( empty($txtInput) ) {
$error_message = 'Input is a required field.'; }
else if ( !is_numeric($txtInput) ) {
$error_message = 'Input must be a valid number.'; }
else if ( $txtInput <= 0 ) {
$error_message = 'Input must be greater than zero.'; }
else {
$error_message = ''; }
Is there a way for the flag to not be thrown up on the pages first load? Any help would be appreciated
Wrap your logic that should only run when a form is submitted in an if block that checks to see if the form is submitted via POST:
if ('POST' === $_SERVER['REQUEST_METHOD']) {
// Form submitted. Put form logic here.
}
I want to show an error (in phpBB it's trigger_error) right after the user clicks submit.
I already have a function which checks if a link has been posted. Now I want to call it after the submit post button has been clicked.
Where do I find that? Probably in posting.php?
Open posting.php.
find around line 631
if ($submit || $preview || $refresh)
{
after add
$post_data['your_url'] = "http://www.damienkeitel.com/index.php"; //remove the equals and url value if using in real post
$your_url = $post_data['your_url'];
$your_url_exists = (isset($your_url)) ? true : false;
$your_url = preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $your_url);
if ($your_url_exists && http_file_exists($your_url) == true)
{
trigger_error('yeah, its reachable');
}
else if ($your_url_exists && http_file_exists($your_url) == false)
{
trigger_error('what da hell..');
}
open functions_posting
find around line 19
/**
* Fill smiley templates (or just the variables) with smilies, either in a window or inline
*/
after add
function http_file_exists($url)
{
$f = #fopen($url,"r");
if($f)
{
fclose($f);
return true;
}
return false;
}
I have a form that updates a user's info. How can I tell the form to NOT update certain fields when left blank?
if(trim($email) == '') { /* don't update */ }
This is better:
if ( empty( trim( $email ) ) )
{
// do not update
}
else
{
// update
...
}
if(trim($email) == '') {}else{ YOUR UPDATE SCRIPT HERE }