I need a form to be able to get dynamic date values from php
My current form looks like the following:
[radio date default:1 "1" "2017-11-16" "2017-11-17" "2017-11-18" "2017-11-20" "2017-11-21"]
Is there any way to use php values instead?
Ideally, I would be able to put something like this in the editor itself
[radio date default:1 "1" "<?php echo date('Y-m-d'); ?>"]
Is this possible?
you can make your own radio button shortcodes with different names you shoud go on this way. not to run php on editor.
you can use this hook
wpcf7_add_shortcode('date_radio_button', 'wpcf7_date_radio_button');
function wpcf7_date_radio_button($tag) {
if (!is_array($tag)) return '';
$name = $tag['name'];
if (empty($name)) return '';
$html = '<input type="radio" name="' . $name . '" value="' . date('Y-m-d') . '" />';
return $html;
}
Here is the simple way to change the value of radio button,
What you need to do is, give an ID to radio button,
For example,
[radio field_name id:date_radio default:1 "1" "2" "3" "4"]
Where I have given ID "date_radio".
Now, in your page, you need to add following jQuery code:
<script>
jQuery(document).ready(function(){
jQuery('#date_radio').find("input[type='radio']").attr('value','<?php echo date('Y-m-d');?>'); // if you are going to put this code in .js file, then you need to get value from hidden field where you need to give date as value.
});
</script>
Make sure, Above code will change the value of all the radio option for given ID.
Please let me know if you need any further help in this.
Thanks!
Related
I would like to know if it is possible to help me please.
It's a live ajax search that retrieves information in the database. This is the php code :
<?php
$key=$_GET['key'];
$array = array();
$connection=mysqli_connect("localhost","root","","visitor_signin_app");
$query = mysqli_query($connection, "SELECT * FROM visitors WHERE visitor_first_name LIKE '%{$key}%' AND visitor_visit_status = 'Signed Out'");
while($row = mysqli_fetch_assoc($query)) {
$array[] = '<span style="display:none; visibility:hidden">'.$row['visitor_id'].'</span>' . ' ' . $row['visitor_first_name'] . ' ' . $row['visitor_last_name'];
}
echo json_encode($array);
mysqli_close($connection);
?>
In the array I am trying to hide the 'visitor_id' and when I start typing the name in the input field it works perfect where it only shows the first name and last name, but once I select the name that displays in the dropdown then it inserts the
<span style="display:none; visibility:hidden">1</span>
So my main question is, would it be possible to hide the html that I dont want to display in the input field but the value needs to be added with the name that gets chosen. Any advice would be gladly appreciated. Thank you
This is the link where I received the code : https://codeforgeek.com/2014/09/ajax-search-box-php-mysql/
I would like to retrieve all the information from the registered person that gets selected in the dropdown list and add them as a new entry to the database.
Why not use the HTML inputwith type hidden ? See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden
I think it's made exactly for your purpose.
Your question is a bit confusing to understand, but if I'm correct, what you want to do is have a hidden input field, but set the value of the input field based on the value of a different input field.
To do that, you should give your hidden field a display: none style, and use JavaScript to set it's value. Something like this:
document.getElementById('inputId').value = 'your data';
Looking for some help with checkbox(switch type) that I have put in PHP.
These checkbox are created dynamically with data received from a MySQL Database.
The checkbox is loaded on the page depending on the condition of the checkbox placed on the database.
Now, I need help to build a code that perform some action like writing back into another database table everytime this checkbox is actioned; i.e. its inital state can be :checked or left blank(unchecked) and each of these checkbox have an ID or value on them from database. But any action that takes place either from blank to :checked or from :checked to blank, it needs to trigger an action for that particular actioned checkbox only.
Would need help on this as PHP please.
My Code Looks like this for a checkbox:
echo "<input type='checkbox' class='input-swtoggle' name='switch-box' ";
$lightStatus = $row->light_status;
if ($lightStatus == "1") {
echo "checked>";
}
else{
echo ">";
}
PS: I did try alot Googling and on Stackoverflow, but none of them are helping for the above condition.
You can bind click event to the checkbox using .on()
$(function(){
$(document).on('click',"input:checkbox.input-swtoggle",function() {
alert($(this).is(':checked'));
});
});
<?php
// HTML code
$checkced = ($row->light_status == '1') ? 'checked="checked"' : '';
echo '<input type="checkbox" class="input-swtoggle" name="switchbox[]"' . $checkced . '/>';
// Code after form posted:
if (! empty($_POST['switchbox'])) {
foreach ($_POST['switchbox'] as $switch) {
// Apply your logic here.
}
}
?>
problem
i have two button "YES" and "NO". if user click YES then text input will appear with value set ex: value="$check['sum'];" but when user click No then text input will appear without value ex: value ="".
here is my code
<input id="test<?php echo $row['br_loc'];?>" value="<?php echo $value;?>" name="test" type="text" class="test" style="width:70px;display:none">
and jquery
$(document).ready(function(){
$("#Yes<?php echo $row['br_loc'];?>").click(function(){
$("#test<?php echo $row['br_loc'];?>").show(1000);
});
$("#No<?php echo $row['br_loc'];?>").click(function(){
$("#test<?php echo $row['br_loc'];?>").hide(1000);
});
thanks you
Try using the disabled attribute:
$("#test<?php echo $row['br_loc'];?>").attr('disabled','disabled');
and
$("#test<?php echo $row['br_loc'];?>").removeAttr('disabled');
Try this:
$(document).ready(function(){
$("#YES").click(function(){
$("#test").show(); //value of input as set before. so, just show
}
$("#NO").click(function(){
$("#test").attr('value','').show(); //set value = '' , and show
}
});
Use binding function so that you provide your JS code with exact parameters. Code like yours should never be used.
Object ID or class should contain alphanumerical characters only, should not begin with number(s), and optionally, - or _ might be used. Avoid spaces or, as you've already shown yourself, using embedded PHP code which is highly unlikely to work in any further project of yours. It's also dangerous.
instead of this code $("#Yes<?php echo $row['br_loc'];?>")
try the following
$("#test<?php echo $row['br_loc'];?>").
Because you used id of button as "test<?php echo $row['br_loc'];?>". so only your click event not worked.
I have an extremely large form with around 200+ input fields, once the form has been completed you can view it in the admin section (copied code from main section).
I really don't want to have manually go through and delete every input field. Is there a way to expand all input fields to the size of the value or input after page load or remove then input tags all together leaving just the value?
If you just want to change all input fields to native text:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$("input").each( function(index)
{
$(this).replaceWith("<p>"+$(this).val()+"</p>");
}
);
});
</script>
This will then remove all input tags all together leaving just the value (with a < p> tag around it )
fiddle:
http://jsfiddle.net/wKvPg/
if you just pasted the code it means that your code is mostly html so in that case i would use a text editor like notepad++ it has a find and replace function which supports regex you can use that
Download Notepad++
On the future i recommend you avoid copy/pasting code and implement them as functions.
You can have hundred or more inputs with same name and different values:
<input type="text" name="values[]" value="val1" />
<input type="text" name="values[]" value="val2" />
Just loop it all:
foreach ($_POST['values'] as $key => $val)
{
print "Key = " . $key . " Value = " . $val . "<br />";
// another actions
}
Or access directly:
$val1 = $_POST['values'][0]; // 'val1'
$val2 = $_POST['values'][1]; // 'val2'
Hope that helps.
I would like to test my button can get the current value from the date's textbox? I got the value of submit button but I couldn't find any code get name of the button. So what should I call I'm able to view the value?
$form_button_layout = '<button class="btn" name="oprf" value="view-log" type="submit">View</button>';
<form class="well form-inline" method="post"<?= $form_action_override; ?>>
If you'd like to get the value of 'oprf' above, then:
$value = $_POST['obrf'];
Should do it in php.
I don't think this works consitently in all browsers. Better to work with a customized name attribute.
You can try this one
if(isset($_POST['oprf'])) {
echo $_POST['oprf'];
}
Hope this helps
Add type property with submit type="submit" to button tag this will submit the form then receive the form inputs value in php script with super global variable $_POST['input name'] or $_GET[] wdepends on from action property value by default GET.
You can do:
if ($_POST['oprf'] == '' || $_POST['oprf'] == NULL) {
//this checks to see if there has been a value that was sent with the
//form
}
I usually use isset for cookies.