It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to design a dynamic form using php. suppose i have created a text box using javascript as follow
var labels=new Array()
function add(type) {
var element = document.createElement("input");
var label=prompt("Enter the name for lable","");
labels.push(label);
document.getElementById('raj').innerHTML=document.getElementById('raj').innerHTML+label;
element.setAttribute("type", type);
element.setAttribute("name",label);
var rohit = document.getElementById("raj");
rohit.appendChild(element);
document.getElementById('raj').innerHTML=document.getElementById('raj').innerHTML+"<br/>";
}
I want to make this field as a required field using php(it is required). what should i do for that
In html5 you can set a required attribute.
element.setAttribute("required", "required");
If you want to use PHP, as mentioned in the question, that would happen on the server side. You have to validate the request received by a php script & check whether it is empty or not.
It's not clear what you want do do, but if you're using POST to send it to PHP then you can check if the value is empty like this
<?php
if(empty($_POST['value_name']))
{
echo 'value is required';
}
else
{
// OK
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a question about checkboxes. I am making a website that lets users enter their tasks for the day and can check the tasks off once they are complete. They can browse the tasks by selecting the date. I am using the AJAX get method to get the tasks from the database and display them in the webpage. I am not sure how to create a checkbox for each task I get from the AJAX method as I will be getting all the tasks for the selected date through one ajax call to the php script that connects to database and returns the tasks. And also how to identify which checkbox corresponds to which task.
In the db there are index numbers, task, date of the task, completed or not and the username
Any help will be greatly appreciated. Thanks
Make a JSON response from your PHP function that is returned with the ajax request and use the response to put the html in your page body.
For example, let's say you have the following PHP code:
<?php
$response = array();
$tasks = array(0 => "Task1", 1 => "Task1", 2 =>
"Task1");
$response['tasks'] = $tasks;
$html = '';
foreach($tasks AS $k => $v) {
$html .= '<input type="checkbox" id="task_' .$v. '" />';
}
$response['html'] = $html;
echo json_encode($response); ?>
?>
And once your AJAX request finoshes, you can put the checkboxes in your page with jQuery(?)
<script type="text/javascript">
yourAjaxFunxtinHere().success(function()
{
$('#container').html(response.html);
});
</script>
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to set a custom message for an input:
$this->form_validation->set_message('username', 'Choose a business, Mang!');
and display this:
<?php echo form_error('username'); ?>
But nothing displays for me, what is wrong?
Is this what I need? Example:
if($result)
{
$this->form_validation->set_message('username', 'Choose a business, Mang!');
}
You need to set rules as such:
$this->form_validation->set_rules('form_field_username', 'username', 'required|callback_business_check');
function business_check($username) {
if(strlen($this->input->post('form_field_business')) == 0) {
$this->form_validation->set_message('business_check', 'Choose a business, Mang!');
return false;
}
return true;
}
This is providing I have the right idea of what you are doing...
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
here is the code for adding to database:
<?php
/*Config*/
Sounds like something that should be able to be easily accomplished using a PHP session variable.
Just use sessions and set a session variable (call it posted or something) and if that variable is set, don't allow the user to post (hide the submit button or use a PHP if-statement in your javascript to only perform the action when that variable is not set).
The session will be cleared when the user closes the browser.
As a possible example, in your PHP code for adding to the database, just put this at the beginning:
session_start();
if (isset($_SESSION['posted']))
die("posted");
$_SESSION['posted'] = true;
EDIT :
You just need to add another else if statement. It will look something like this:
if(response == "knownudid"){
document.getElementById('udid_message').innerHTML = '<br><i><font color="red">This UDID has already been inserted and it is valid.</font></i>' ;
}else if(response == "noudid"){
document.getElementById('udid_message').innerHTML = '<br><i><font color="orange">Please, enter your UDID.</font></i>' ;
}else if(response == "errudid"){
document.getElementById('udid_message').innerHTML = '<br><i><font color="red">It seems this UDID is not correct. Please check for typo.</font></i>' ;
}else if(response == "validatedudid"){
document.getElementById('udid_message').innerHTML = '<br><i><font color="green">This UDID has been found as an invalid one. Now it is valid.</font></i>' ;
}else if(response == "posted"){ // Here is the new one
document.getElementById('udid_message').innerHTML = '<br><i><font color="red">You have already posted a UDID for this session.</font></i>' ;
}else{
document.getElementById('udid_message').innerHTML = '<br><i><font color="green">UDID <b>'+response+'</b> successfully inserted.</font></i>';
}
With some nice jQuery or js you could hide the form after the user submit.
Having the javascript within the HTML elements is bad, move it into the <script> tags or even better, a separate .js file.
For HTML5 browsers, placeholder is a much more elegant way of providing instructions for text fields.
If you're using AJAX to submit the form, within your function insert_udid() add:
.
document.getElementById('your_button_or_form').disabled = true;
// or document.getElementById('your_form').style.visibility = 'hidden';
...otherwise, you'll need for the php code to disable or omit the form from the response HTML.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
My pseudo code is as follows:
if($_GET['action'] == 'list'){
do function getFileList($dir)
else
do nothing
exit;
}
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
}
Your psuedo code is almost there.
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
/* ... */
}
if($_GET['action'] == 'list') {
getFileList($dir);
}
Are you asking how to send a variable via GET to a PHP file from within the same PHP file? You can create a form that submits to itself: http://www.tellingmachine.com/post/Simple-self-submitting-PHP-forms.aspx.
If you are looking to do something else, please provide additional details.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I found a great contact form over here. How to show a "Successfully sent" message right under the contact from instead of using a redirect to an other page?
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
Change the form process code to this.
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
$successful = false;
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$successful = true;
}
}
Where you want the message to show.
if($successful){
echo "Successfully sent.";
}