How to disable submit button once it has been clicked php? - php

I have a send button at the end of the form but I do not know how to disable it in the onClick.
echo "<input type='submit' name='add' value=\"".$LANG['help'][14]."\" class='submit' >";

you can use
echo "<input type='submit' name='add' onclick="this.form.submit(); this.disabled = true;" value=\"".$LANG['help'][14]."\" class='submit' >";

You can try following code
echo "<input type='submit' name='add' onclick="this.disabled = true; this.form.submit();" value=\"".$LANG['help'][14]."\" class='submit' >";

please try this
$('input[type="submit"]').click(function() {
this.disabled = true;
};

Related

In echo sumbit button not redirecting in php

echo html code onclick of button redirection.
I have tried by using button and input tags both.
while($_row = $result->fetch_assoc())
{
echo "<input type=\"checkbox\" value=\"".$_row['id']."\">" . $_row['id'] ." ".$_row['name'].' '.$_row['contact'].'';
echo"<input type='button' value='DELETE' onclick='document.location.href='/project1/delete.php''";
echo"?id=".$_row['id'];
echo" />";
echo"<input type='button' value='EDIT' onclick='document.location.href='/project1/edit.php''";
echo"?id=".$_row['id'];
echo" /><br>";
$id=$_row['id'];
}
1- In your code 'Unexpected end of input' issue is there with onclick.
2- you can use concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side. and last display the output.
<?php
while($_row = $result->fetch_assoc())
{
$id = $_row['id'];
$name = $_row['name'];
$contact = $_row['contact'];
$output ='';
$output.="<input type=\"checkbox\" value=\"".$id."\">" . $id ." ".$name.' '.$contact;
$output.="<input type='button' value='DELETE' onclick=\"document.location.href='/project1/delete.php?id=$id'\"/>";
$output.="<input type='button' value='EDIT' onclick=\"document.location.href='/project1/edit.php?id=$id'\"/>";
$output.="<br/>";
echo $output;
}
?>
Replace with following code:
echo"<input type='button' value='EDIT' onclick='document.location.href=\"/project1/edit.php";
echo "?id=1\"'";
echo" /><br>";
?>

How to get the values of the radio buttons with variable names in php?

This code gets some data from the database and displays it with a group of radio buttons. How do I get the value for every group of radio buttons??
<form name="functional" method="post" action="funcsub.php">
<?php
$n=0;
$con=mysqli_connect('localhost','Sanjana','sanjana');
mysqli_select_db($con,'mydatabase');
$sql = mysqli_query($con,"select * from functional") or die("Failed");
while($result = mysqli_fetch_array($sql)){
?>
<br/>
<?php
echo $result["Skill"];
echo "</br>";
echo"<input type='radio' name='tech[.$n.]' value='0'>0";
echo"<input type='radio' name='tech[.$n.]' value='1'>1";
echo"<input type='radio' name='tech[.$n.]' value='2'>2";
echo"<input type='radio' name='tech[.$n.]' value='3'>3";
echo"<input type='radio' name='tech[.$n.]' value='4'>4";
echo"<input type='radio' name='tech[.$n.]' value='5'>5";
$n=$n+1;
}
?>
<br/>
<input type="submit" name="submit" value="Submit">
</form>
Those dots are not needed in these. Perhaps you meant?:
echo "<input type='radio' name='tech[".$n."]' value='0'>0";
echo "<input type='radio' name='tech[".$n."]' value='1'>1";
echo "<input type='radio' name='tech[".$n."]' value='2'>2";
echo "<input type='radio' name='tech[".$n."]' value='3'>3";
echo "<input type='radio' name='tech[".$n."]' value='4'>4";
echo "<input type='radio' name='tech[".$n."]' value='5'>5";
Assuming that's what you wanted, you can get values like this (I prefer writing above the printing part (or your form, in this case)):
if (!empty($_POST)) {
$tech = $_POST['tech'];
echo 'Value of the second row: '.$tech[1];
}

Echo Submit Button in PHP

I am trying to echo a submit form in my php code:
I am trying the following:
// Display results
foreach ($media->data as $data) {
echo "<a href=\"{$data->link}\"</a>";
echo "<h4>Photo by: {$data->user->username}</h6>";
echo $pictureImage = "<img src=\"{$data->images->thumbnail->url}\">";
echo "<h5>Like Count for Photo: {$data->likes->count}</h5>";
echo "<form>";
echo "<form action='tag.php' method='post'>";
echo "<input type='submit' name='submit'>";
echo "</form>";
}
Then:
if(isset($_POST['submit'])) {
echo "hello";
}
This doesn't seem to echo "hello";
Any help would be appreciated
You're missing a closing parenthesis:
if(isset($_POST['submit'])) {
^
Here
You're missing a value on the input tag. Change it to:
echo "<input type='submit' name='submit' value='Submit'>";
echo '<input type="submit" class="btn btn-primary" value="Active">';
It should be
if(isset($_POST['submit'])) {
^
echo "hello";
}
you missed a parenthesis.
Edit: Also it should be:
<input type='submit' name='submit' value='submit'>
Else $_POST['submit'] will not get set.

Ask if you are sure you want to submit? JavaScript?

I currently have this.
//other stuff up here - not important
echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='1' /><input type='hidden' name='id' value='" . $id . "' /><input type='submit' name='Redeem' value='Redeem'></form></td>";
} else {
echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='0' /><input type='hidden' name='id' value='" . $id . "' /><input type='submit' name='Un-Redeem' value='Un-Redeem'></form></td>";
//other stuff down here - not important
and I want to change it so that when you press:
a) the 'Redeem' SUBMIT button it alerts you saying, "Are you sure you want to Redeem?"
b) the 'Un-Redeem' SUBMIT button it alerts you saying, "Are you sure you want to Un-Redeem?"
I have tried a few of them including the ONCLICK on the submit but none worked.. and I believe that is because I have it in an ECHO and I had to remove the (") quotation marks which stopped the function from happening.
Anyone know another way I can do it?
You can use the Javascript confirm function.
if(confirm("Are you sure you want to Redeem?")) {
// do something
} else {
// do something
}
You can also do this on form submit by adding the following code to your form:
onsubmit="return confirm('Are you sure you want to Redeem?');"
The form will only submit if the user clicks "OK".
Here is the solution :
//other stuff up here - not important
echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='1' /><input type='hidden' name='id' value='" . $id . "' />
<input type='submit' name='Redeem' value='Redeem' onclick="return confirm('Are you sure you want to Redeem?')"></form></td>";
} else {
echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='0' /><input type='hidden' name='id' value='" . $id . "' />
<input type='submit' name='Un-Redeem' value='Un-Redeem' onclick="return confirm('Are you sure you want to Un-Redeem?')" ></form></td>";
//other stuff down here - not important
Edit:
Added escaping character in here:
//other stuff up here - not important
echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='1' /><input type='hidden' name='id' value='" . $id . "' />
<input type='submit' name='Redeem' value='Redeem' onclick=\"return confirm('Are you sure you want to Redeem?')\"></form></td>";
} else {
echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='0' /><input type='hidden' name='id' value='" . $id . "' />
<input type='submit' name='Un-Redeem' value='Un-Redeem' onclick=\"return confirm('Are you sure you want to Un-Redeem?')\" ></form></td>";
//other stuff down here - not important
Use the javascript confirm function. The form won't submit if the confirm returns false.
<form action='redeem.php' method='post' id='form' onSubmit="return confirm('Are you sure you want to redeem')">
If you want to do something else if the user clicks cancel then you'll need to create a custom function:
function my_confirm() {
if( confirm("Are you sure you want to redeem?") ) {
return true;
}
else {
// do something
return false;
}
}
And on the form tag:
onSubmit="return my_confirm()"

javascript cannot redirect in php

I have created a form below and some javascript code in php, the it doesnt redirect to other pages.
<form method="post" name="for">
<?php
echo "<input type='text' name='text1'><input type='submit' name='submit' value='go' onclick='fon1();'>";
?>
</form>
<?php
echo "<script type='text/javascript'>";
echo "function fon1(){";
echo "var k = confirm('Confirm Delete');";
echo "if(k == true){";
echo "window.location = 'http://www.google.com'; }";
echo "else{ window.location = 'http://www.yahoo.com';} ";
echo "}</script>";
?>
Put a "return false;" after calling fon1();
echo "<input type='text' name='text1'><input type='submit' name='submit' value='go' onclick='fon1(); return false;'>";
Use
window.location.href
instead of
window.location
I think you change the type of your form buttom from "submit" to "button" :
echo "<input type='text' name='text1'><input type='button' name='submit' value='go' onclick='fon1();'>";
try this!
you can use window.location.replace to simulate a redirect (back button won't work)
or window.location.href so simulate a click
Do this:
<form method="post" name="for">
<?php
echo "<input type='text' name='text1'><input type='button' name='submit' value='go' onclick='return fon1();'>";
?>
</form>
<?php
echo "<script type='text/javascript'>";
echo "function fon1(){";
echo "var k = confirm('Confirm Delete');";
echo "if(k == true){";
echo "location.href = 'http://www.google.com'; }";
echo "else{ window.location = 'http://www.yahoo.com';} ";
echo "}";
?>
<form method="post" name="for">
<?php
echo "<input type='text' name='text1'><input type='button' name='submit' value='go' onclick='fon1();'>";
?>
</form>
<script type='text/javascript'>
function fon1(){
var k = confirm('Confirm Delete');
if(k == true){
document.location = 'http://www.google.com';
}
else
{
document.location = 'http://www.yahoo.com';
}
}</script>
Just use this..
<form method="post" name="for">
<?php
echo "<input type='text' name='text1'><input type='button' name='submit' value='go' onclick='fon1();'>";
?>
</form>
<script type='text/javascript'>
function fon1(){
if(confirm('Confirm Delete')) {;
document.location.href = 'http://www.google.com';
}
else {
document.location.href = 'http://www.yahoo.com';
}
}
</script>

Categories