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>
Related
So, I'm making a PHP page. I'm trying to get a url like this
https://nikkiedev.com/folder/indexfile/?schedule-btn=true&time-zone=CET
but instead, when I click on my GET form for the time zone it goes to
https://nikkiedev.com/folder/indexfile/?time-zone=CET
Here's my code:
<div class='mobile-center'>
<form method="GET">
<button name="schedule-btn" type="submit" value="true" class="btn">schedule</button>
<button name="roles-btn" type="submit" value="true" class="btn">roles</button>
</form>
<?php
$sched_btn = $_GET["schedule-btn"];
$roles_btn = $_GET["roles-btn"];
if (isset($sched_btn)) {
echo "<div class='mobile-center'>";
echo "<h1>Change schedule</h1>";
echo "<hr>";
echo "<p>Choose time zone</p>";
echo "<form method='GET'>";
echo "<p>
<input type='radio' name='time-zone' value='CET'> CET
<input type='radio' name='time-zone' value='EST'> EST
<input type='submit'>
</p>";
echo "</form>";
$timezone = $_GET["time-zone"];
echo "</div>";
if ($timezone == "CET") {
echo "<h1>CET</h1>";
}
else if ($timezone == "EST") {
echo "<h1>EST</h1>";
}
}
?>
</div>
Add the value of $sched_btn as a hidden input in the new form.
if (isset($sched_btn)) {
echo "<div class='mobile-center'>";
echo "<h1>Change schedule</h1>";
echo "<hr>";
echo "<p>Choose time zone</p>";
echo "<form method='GET'>";
echo "<input type='hidden' name='schedule-btn' value='$sched_btn'>";
echo "<p>
<input type='radio' name='time-zone' value='CET'> CET
<input type='radio' name='time-zone' value='EST'> EST
<input type='submit'>
</p>";
echo "</form>";
$timezone = $_GET["time-zone"];
echo "</div>";
if ($timezone == "CET") {
echo "<h1>CET</h1>";
}
else if ($timezone == "EST") {
echo "<h1>EST</h1>";
}
}
while($row = mysql_fetch_assoc($req))
{
$user_from = $row['user_from'];
echo "<form method='post'><a href='".$row['user_from']."' name='yo' value'".$row['user_from']."'>".$row['user_from']."</a>  ";
echo "<input type='submit' name='acc' value='Accept'>   <input type='submit' name='cancel' value='Reject Rrquest'></form> <br/><br/>";
}
if(isset($_POST['acc']))
{
}
Blockquote
//on submit here i need to disply corresponding $row['user_from']
value
Use <input type="hidden" name="whateveryouwant" />, if you don't want to display text field to user.
Try this:
while($row = mysql_fetch_assoc($req))
{
$user_from = $row['user_from'];
echo "<form method='post'><input type='hidden' name='user_from' value='".$row['user_from']."' /><a href='".$row['user_from']."' name='yo' value'".$row['user_from']."'>".$row['user_from']."</a>  ";
echo "<input type='submit' name='acc' value='Accept'>   <input type='submit' name='cancel' value='Reject Rrquest'></form> <br/><br/>";
}
if(isset($_POST['acc']))
{
echo $_POST['user_from'];//echo the value of user_form
}
<?php
while($row = mysql_fetch_assoc($req))
{
$user_from = $row['user_from'];
?>
<form method="post" action="">
<?php $row['user_from'] ?>
<input type="submit" name="acc" value="Accept">
<input type="submit" name="cancel" value="Reject Rrquest">
</form>
<php
}
?>
<?php
if(isset($_POST['acc']) && !empty($_POST['yo']))
{
$link = $_POST['yo'];
// do what you want to do with this `url`
}
?>
NOTE: Don't Complex Your Code With Using Html COde In Php echo. You Can Just Open the While Loop Brackets { and then close the php ?> then simple html you have to written, So Just Avoid to used html code inside the php echo
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;
};
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.
I have this and works fine. But can someone tell me is there a SMARTER way to validate this?
In the validation here, you may find that the echo "<form....... is replicated thrice to make sure that the form content is also visible along side the validation message when the form is submitted. Im sure there is a more refined method of validating text box content without form being replicated multiple times.
Also appreciate if some one can suggest me a method to retain the text box value after the form is being submitted. Usually when the form is submitted the value you enter disappears.
Thanks
<?php
include ("../connection/index.php");
?>
<form method='post' action=''>
<input type="submit" name="sendone" id="sendone" value="OneClick">
</form>
<?php
if(isset($_POST['sendone']))
{
echo "Hello";
echo "<form method='post' action=''><input type='text' name='txt1' id='txt1'><input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'></form>";
}
if(isset($_POST['sendtwo']))
{if($_POST['txt1']=='')
{
echo "Hello";
echo "<form method='post' action=''><input type='text' name='txt1' id='txt1'><input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'></form>";
echo "Empty";}
else
{
echo "Hello";
echo "<form method='post' action=''><input type='text' name='txt1' id='txt1'><input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'></form>";
echo "Hit success!";
}}
?>
EDIT
Concept
<hard coded submit1 button>
<dynamically create a text box with a submit2 button>
<when submit2 is activated is should validate the text box content>
When the validation happens both the vaidated message and the text box should be visible
did you mean something like this?
<?php
if(isset($_POST['sendtwo']))
{
echo "Hello";
}
?>
<form method='post' action=''>
<?php
if (!isset($_POST['sendone'])) {
?>
<input type="submit" name="sendone" id="sendone" value="OneClick">
<?
} else {
?>
<input type="hidden" name="sendone" id="sendone" value="OneClick">
<input type='text' name='txt1' id='txt1'<?=isset($_POST['txt1']) && trim($_POST['txt1']) !== '' ? ' value="'.trim($_POST['txt1']).'"' : ''?>>
<input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>
<?
}
?>
</form>
<?php
if (isset($_POST['sendtwo'])) {
if (trim($_POST['txt1']) == '') {
echo 'Empty';
} else {
echo 'Hit success!';
}
}