I currently have this login page.
<form action='http://localhost:8080/iSchedj/API/api.php' method='post'>
<fieldset>
<p>
<label for='username'>Username</label>
<input type='text' id='username' name='username' value='' maxlength='20' />
</p>
<p>
<label for='password'>Password</label>
<input type='password' id='password' name='password' value='' maxlength='40' />
</p>
<p>
<input type='hidden' name='form_token' value='<?php echo $form_token; ?>' />
<input type='submit' name='login' id='login' value='Login' />
</p>
</fieldset>
</form>
On submit, I have a function on the server-side where I analyze the data and check if there are any issues.
Problem is, I would like to send a response back to the client and re render the login page if any issues occurred with a response saying 'Error on login'.
I am having an issue with the response part.
On the server side, I just run this when an error is found in the form
header( 'Location: http://localhost:8080/iSchedj/index.php');
echo 'Incorrect Length for Password';
which redirects the client to the login page. But how do I send the error message to the page as well? The echo message is no where to be found.
Add it to the URL and display your error message via JavaScript.
header( 'Location: http://localhost:8080/iSchedj/index.php#error=1');
Your JS script will need to look at the document.location.hash and behave accordingly.
Related
I was wondering if anyone knows how to automatically refresh a webpage after clicking on a form submit button rather than being taken to a .php page?
Here's my html:
<p>
<form action='action.php' method='post'>
<textarea name='message' rows='3' cols='30'>
</textarea><br><br>
<input type='SUBMIT' value='Submit' />
</p>
Here's my php:
<?php
$message = $_POST['message'];
mail("name#website.com","", $message)
?>
Any help much appreciated,
Guy Brown
If you want you can do it in same file where form is located like this (if form is located in action.php or change action.php to php self as suggested):
<p>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
<textarea name='message' rows='3' cols='30'>
</textarea><br><br>
<input type='SUBMIT' value='Submit' />
</form>
</p>
<?php
if(isset($_POST['message'])) {
$message = $_POST['message'];
mail("name#website.com","", $message)
}
?>
how to reset value with jquery form..my input text value with php. when I edit text and I reset, then back again to the value php..I've tried with jquery reset but input text
lost value.
<form>
<input type='text' id='chk' value='<?php echo $item.$i?>'/><br/>
<input type='text' value='<?php echo $item.$i?>'/><br/>
<input type='text' value='<?php echo $item.$i?>'/><br/>
<input type='reset' id='reset_button' value='reset'/>
</form>
when i edit input text and then i click reset.input text losing value?how to input text back to original value?
thanks..
You could use a form reset button: <input type='reset' value='Reset'/>
If you don't want the button to be visible, you could hide the button and call the click() method to reset the form.
Example:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>With button:</h2>
<form>
<input type='text' value='Foo'/><br/>
<input type='text' value='Bar'/><br/>
<input type='reset' value='Reset'/>
</form>
<br/>
<br/>
<h2>Without button:</h2>
<form>
<input type='text' id='chk' value='1'/><br/>
<input type='text' value='Foo'/><br/>
<input type='text' value='Bar'/><br/>
<input type='reset' id='reset_button' style='display: none;'/>
<input type='submit' onclick="if ($('#chk').val() == '0') $('#reset_button').click(); return false;" value='Check if 1 (reset if 0)'/>
</form>
I'm trying to build a php contact form (to be used into a wordpress custom page) that show a different "thank you message" based on the checkbox selection.
There will be three checkbox, every checkbox in used will make appear a download link under the "thank you" message.
<form method="post" action="php/contact-send.php" id="contact_form">
<p><label class="form_label" for='form_name'>Name</label>
<input id='form_name' type='text' name='name' class="textbox" value='' /></p>
<p><label class="form_label" for='form_email'>E-mail</label>
<input id='form_email' type='text' name='email' class="textbox" value='' /></p>
<p>Download1 <input id='form_name' type='checkbox' name='Download1' class="textbox" value='Download1' /></p>
<input id='form_submit' type='submit' name='submit' value='Send message' />
<!-- To Email -->
<input id='to_email' type='hidden' name='to_email' value='<?php echo "";?>' />
<!-- hidden input for basic spam protection -->
<div class='hide'>
<label for='spamCheck'>Do not fill out this field</label>
<input id="spamCheck" name='spam_check' type='text' value='' />
</div>
</form>
<!-- contact form ends here-->
<!-- This div will be shown if mail was sent successfully -->
<div class="hide success">
<p><?php echo thanks_message;?></p>
<p>
<?php
if(isset($_POST['Download1'])) {
// The checkbox was enabled...
echo "Link download 1";}
else { echo "much wrong, wow";}
?>
</p>
The problem is i can't get it to work and detect when the first checkbox is selected, it alway give me the else message even if i select it. I'm kinda new with php and i don't really get what i'm doing wrong,
Thanks in advance for any help
Before I am told to look at other posts that are similar, please note that I have tried to apply them but to no avail.
I need to clear the variables in the url after a series of if statements are true. I have the following code:
<?php
$_SESSION['passlevel']='0';
if ($_SESSION['passlevel'] == '0')
{
if(isset($_GET['box_1_color']))
{
$color=$_GET['box_1_color'];
if($color == "#800080")
{
echo "you have passed step one.";
$_SESSION['passlevel'] = '1';
// add something that removes url string
}
else
{
echo "you didn't select purple.";
}
}
else echo "login with your colorlock passcode.";
}
if ($_SESSION['passlevel'] == '1')
{
if(isset($_GET['box_1_color']))
{
$color=$_GET['box_1_color'];
if($color == "#DD7500")
{
echo "you have passed step two.";
$_SESSION['passlevel']='2';
// add something that removes url string
}
else
{
echo "you didn't select orange.";
}
}
else echo "enter remaining colors.";
}
?>
This is for color dependent password that has the background of each of 10 divs change to one of 10 colors after a div is clicked on (note that some of the echoes are only there for now as a method of debugging). The information is sent to the url through multiple forms:
<form>
<div id="box1" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box1color ?>'/>
<input type='hidden' name='name' value='box1color'/>
</form>
<form>
<div id="box2" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box2color ?>'/>
<input type='hidden' name='name' value='box2color'/>
</form>
<form>
<div id="box3" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box3color ?>'/>
<input type='hidden' name='name' value='box3color'/>
</form>
<form>
<div id="box4" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box4color ?>'/>
<input type='hidden' name='name' value='box4color'/>
</form>
<form>
<div id="box5" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box5color ?>'/>
<input type='hidden' name='name' value='box5color'/>
</form>
<form>
<div id="box6" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box6color ?>'/>
<input type='hidden' name='name' value='box6color'/>
</form>
<form>
<div id="box7" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box7color ?>'/>
<input type='hidden' name='name' value='box7color'/>
</form>
<form>
<div id="box8" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box8color ?>'/>
<input type='hidden' name='name' value='box8color'/>
</form>
<form>
<div id="box9" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box9color ?>'/>
<input type='hidden' name='name' value='box9color'/>
</form>
<form>
<div id="box10" class="box" onclick='this.parentNode.submit()'></div>
<input type='hidden' name='box_1_color' value='<?php echo $box10color ?>'/>
<input type='hidden' name='name' value='box10color'/>
</form>
An example of the url after one of the colors (purple) is selected:
http://localhost/colorlock/index.php?box_1_color=%23800080&name=box9color
So I want to remove the ?box_1_color=%23800080&name=box9color part. How could i remove it where the code says "// add something that removes url string" so that when the next block of code is initiated it doesnt run immediately with the same color code in the url before a user can select their next color?
I hope my question is clear (i understand that it a confusing) and i hope that it is answerable. Thank you.
You need to do one/some of 3 things:
Use POST. This is a good idea but it would still be best combined with...
Redirect to the same page without the URL arguments after processing the form.
Use ajax to process the user input.
The easiest of these to integrate with your existing code is probably a combination of 1 and 2. To do this, add these lines where your comment is:
header("HTTP/1.1 303 See Other");
header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}");
exit;
...and change all the <form> elements in your HTML so that they read:
<form method="post">
...and obviously change all occurrences of $_GET in your PHP code to $_POST
Could you use POST instead of GET? You use $_POST in your PHP instead of $_GET and you never have to worry about what's in the URL - it's always clean.
Try
unset($_GET['box_1_color']);
in aproriate place of your code
i am trying to make the login form in my website appears in the middle of the page with gray background, so i have done it like that:
<style type="text/css">
#cover5{position:absolute;top:0px;left:0px;overflow:hidden;display:none;width:100%;height:100%;background-color:gray;text-align:center}
#warning{top: 150px;margin:auto;position:relative;width:600px;height:fit-content;background-color:white;color:black;padding:10px; zIndex:20; border: 5px solid #003366;}
</style
<div id="cover5" onclick="javascript:cover5();">
<div id="warning" onclick="javascript:cover5();">
<?php include 'SignIn.php'; ?>
</div>
</div>
<script>
function cover5()
{
var cover=document.getElementById('cover5');
if(vis)
{
vis=0;
cover.style.display='block';
}
else
{
vis=1;
cover.style.display='none';
}
}
</script>
an this the code of the SignIn.php
<form id='login' action='SignIn.php' method='post' accept-charset='UTF-8' onsubmit="return valid()">
<fieldset >
<legend>SignIn</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >Email:</label>
<input type='text' name='email' id='username' maxlength="50" /> <br />
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" /> <br />
<input type='submit' name='Submit' value='Login' /> <br />
<a href='resetPassword1.php'> Forgot/Reset Password? Click Here</a>
</fieldset>
</form>
the problem is that when use clicks on Forgot/Reset Password? or enter wrong data everything opens in new window, i have used iframe instead of div however when the use signIn successfully the home page opens in the same iframe, so anyone know how to solve the problem?
sorry for the long question :)
You need to add this to your link:
target='_self'
so it would look like this:
<a href='resetPassword1.php' target='_self'> Forgot/Reset Password? Click Here</a>
there are others you can play with too, like to open in new window:
target='_blank'
hope this helps
inside of the link try setting target="_self" so
Forgot/Reset Password? Click Here
If that doesn't work try it in another browser. Sometimes browsers have default settings that could mess stuff up. Another possible problem may be Javascript somewhere in your site sending your links to new windows.