php isset not working properly echo back empty - php

in my code when i click on submit 3 btn it echos back empty $email though post is created in db the title is always empty, however if i change if(isset($_POST['submit3'])) to if(isset($_POST['submit1'])), it doesn't enter the details into db or echo back anything
<script type="text/javascript">
$( document ).ready(function() {
$("#form1").show();
$("#form2").hide();
$("#form3").hide();
$('button[name="submit1"]').click(function(e) {
$("#form2").show();
$("#form1").hide();
$("#form3").hide();
e.preventDefault();
});
$('button[name="submit2"]').click(function(e) {
$("#form3").show();
$("#form1").hide();
$("#form2").hide();
e.preventDefault();
});
});
</script>
<body>
<form id="form1" method="post" >
<div>
<input type="text" id="inputemail" name="email" placeholder="Email" height="34px" >
</div>
<div >
<button id="submit1" type="submit" name="submit1" ><strong>Start</strong></button>
</div>
</form>
<form id="form2" method="post" style="display:none">
<div>
<input type="text" id="inputpwd" name="pwd" placeholder="Password" height="34px" required>
</div>
<div >
<button id="submit2" type="submit" name="submit2" ><strong>Next</strong></button>
</div>
</form>
<form id="form3" method="post" style="display:none">
<div required>
<input type="checkbox" value="0" name="book_type[]"> Romance</input><br>
<input type="checkbox" value="1" name="book_type[]"> Action</input><br>
<input type="checkbox" value="2" name="book_type[]"> suspense</input><br>
<input type="checkbox" value="3" name="book_type[]"> thriller</input><br>
</div>
<div >
<button id="submit3" type="submit" name="submit3" onclick="submitform();"><strong>Next</strong></button>
</div>
</form>
</body>
<?php
$email=$_POST['email'];
$pwd=$_POST['pwd'];
$bookchk=array();
$todaydate = new DateTime();
$todaydate =$todaydate->format('Y-m-d H-i-s');
if(isset($_POST['submit3']))
{
echo $email;
$formarg= array('post_type'=>'details',
'post_title'=>$email,
'post_author'=>'1',
'post_status'=>'publish',
'post_date'=>$todaydate );
$wpdb->insert('wp_posts',$formarg);
$bookpostid=$wpdb->insert_id;
foreach($_POST['book_type'] as $selectedplan)
{
$bookchk[]=$selectedplan;
}
update_field('field_561b9999ebb56',$bookchk[0],$contestpostid);
update_field('pwd',$pwd,$bookpostid);
}
?>

Try it:
<button id="submit3" type="submit" name="submit3" value="Next" onclick="submitform();"><strong>Next</strong></button>

<?php
session_start();
if(isset($_POST['email'])){$_SESSION["email"] = $_POST['email'];}
if(isset($_POST['pwd'])){$_SESSION["pwd"] = $_POST['pwd'];}
if(isset($_POST['book_type'])){$_SESSION["book_type"] = $_POST['book_type'];}
if(isset($_SESSION["email"]) && isset($_SESSION["pwd"]) && isset($_SESSION["book_type"])){
echo "email:".$_SESSION["email"]."<br>";
echo "pwd:" .$_SESSION["pwd"]."<br>";
echo("options:");
for($i=0;$i<sizeof($_SESSION["book_type"]);$i++){
echo $_SESSION["book_type"][$i]."|";
}
session_destroy();
$_SESSION["email"] = "";
$_SESSION["pwd"] = "";
$_SESSION["book_type"] = "";
}
$todaydate = new DateTime();
$todaydate =$todaydate->format('Y-m-d H-i-s');
?>
<body>
<?php if(empty($_SESSION["email"])):?>
<form id="form1" method="post">
<div>
<input type="text" id="email" name="email" placeholder="Email" height="34px" >
</div>
<div >
<input id="submit1" type="submit" name="submit1" value = "Start">
</div>
</form>
<?php endif;?>
<?php if(isset($_SESSION["email"]) && empty($_SESSION["pwd"]) ):?>
<form id="form2" method="post">
<div>
<input type="text" id="pwd" name="pwd" placeholder="Password" height="34px" required>
</div>
<div >
<input id="submit2" type="submit" name="submit2" value = "Next">
</div>
</form>
<?php endif;?>
<?php if(isset($_SESSION["email"]) && isset($_SESSION["pwd"]) && empty($_SESSION["book_type"])):?>
<form id="form3" method="post">
<div required>
<input type="checkbox" value="0" name="book_type[]"> Romance</input><br>
<input type="checkbox" value="1" name="book_type[]"> Action</input><br>
<input type="checkbox" value="2" name="book_type[]"> suspense</input><br>
<input type="checkbox" value="3" name="book_type[]"> thriller</input><br>
</div>
<div >
<button id="submit3" type="submit" name="submit3" onclick="submitform();"><strong>Next</strong></button>
</div>
</form>
<?php endif;?>
</body>

You are getting back empty $email when submitting through button
id="submit3" because an input field with attribute name="email"
doesn't exists within your third form <form id="form3" ...> </form>
You are receving nothing when submitting through button
id="submit1" because e.preventDefault(); method prevents form from
submitting when you click submit button.
To proceed submitting of your first and second form remove e.preventDefault(); from submit button click handlers

Related

PHP to reload page from modal

i am trying to reload page using onClick="location.href='Edit_Equip.php?txtidforsite='" /> but i get Notice: Undefined variable: id
i have tried to define id but still get errors any help would be great
<?php
include('connect.php');
if(isset($_POST['txtidforsite']))
{
$id=$_POST['txtidforsite'];
if(isset($_POST['submit']))
{
$query3 = mysql_query("UPDATE ftn_site_equip SET siteidequip='".$_POST['txtidforsite']."', patype='".$_POST['txtpa']."', drxtype='".$_POST['txtdrx']."' WHERE siteidequip='$id'");
if($query3)
{
header('refresh:2; url=#openModa3');
}
}
$query1=mysql_query("select * from ftn_site_equip where siteidequip='$id'");
$query2=mysql_fetch_array($query1);
?>
<form method="post" action="" align="center">
<input name="txtidforsite" value="<?php echo $query2['siteidequip']; ?>" size="36" class="siteinfotable"/>
<input name="txtdrx" value="<?php echo $query2['drxtype']; ?>" size="36" class="siteinfotable"/>
<input name="txtpa" value="<?php echo $query2['patype']; ?>" size="36" class="siteinfotable"/>
<input type="submit" name="submit" class="update_record_button" value="Update Record" onclick="window.location='#openModal2';" />
</form>
<?php
}
?>
<div id="openModal" class="cancel_modal">
<div align="center">
<h2 align="center">Are you sure you want to cancel all changes ?</h2>
<input name="yes" type="button" value="Yes" class="yes_button" onClick="location.href='Edit_Form.php?txtid='" />
<input name="no" type="button" value="No" class="no_button" onclick="location.href='#close'"/>
</div>
</div>
<div id="openModal2" class="cancel_modal">
<div align="center">
<img alt="" src="Images/tick.jpg"/><br/>
<h2 align="center">Record Successfully Updated</h2>
</div>
</div>
<div id="openModa3" class="cancel_modal">
<div align="center">
<h2 align="center">What Next ?</h2>
<input name="yes" type="button" value="Retrun to Site Information" class="yes_button" onClick="location.href='Edit_Equip.php?txtidforsite=<?php echo $id; ?>'" />
<input name="no" type="button" value="Search for Another Site" class="no_button" onclick="location.href='search.php'"/>
</div>
</div>

Cannot show data from PHP session

My point is after sending form show session data.
form.html:
<form action="sendForm.php" name="f" method="post" onsubmit="return sendForm()" >
<div class="form">
<label for="imie">Name</label>
<input type="text" id="nam" name="nam"/><br/>
<label for="nazwisko">Surname</label>
<input type="text" id="surname" name="surname"/><br/>
</div>
<input type="submit" name="send" id="send" value="send form"/><br/><br/>
</form>
sendForm.php:
<?php
session_start();
$_SESSION['nam'] = $_POST['nam'];
$_SESSION['surname'] = $_POST['surname'];
header("Location: view-struct.php");
?>
view-struct.php:
<span class="label">Name</span><?php echo $_SESSION['nam']; ?><br/>
<span class="label">Surname</span><?php echo $_SESSION['surname']; ?><br/>
[EDIT] Question is closed, forgot to add for session_start() in view-struct.php

Getting a value from dynamically created textbox through php

I have n number of text box (n may be any number) with same name. And
I want to access the value of all the text box of that name.
Ex-:
<form method="post" id="create">
<input type="text" name="user[]" />
<input type="text" name="user[]" />
<input type="text" name="user[]" />
<input type="button" id="newFieldBtn"/>
<input type="submit" name="save" value="save"/>
</form>
jQuery
<script>
jQuery(document).ready(function($) {
$('#newFieldBtn').click(function(){
var code='<input type="text" name="user[]" />';
jQuery('#create').append(code);
</script>
or is there any other way to access the value of the text box. Either
by class or any other property..
<script>
jQuery(document).ready(function($) {
$('#newFieldBtn').click(function(){
var count = document.getElementById('count').value;
count++;
var code = '<input type="text" name="user'+count+'" />';
jQuery('#create').append(code);
document.getElementById('count').value = count;
</script>
and your html like...
<form method="post" id="create">
<input type="hidden" id="count" value="0" name="count">
<input type="button" id="newFieldBtn"/>
<input type="submit" name="save" value="save"/>
</form>
and in your php code...
<?php
if(isset($_POST))
{
$count = $_POST['count'];
for($i=1;$i<=$count;$i++)
{
$user.$i = $_POST['user'.$i];
}
}
?>
Try this one, it will show you the values :
<form action="#" method="post">
<input type="text" name="user[]" />
<input type="text" name="user[]" />
<input type="text" name="user[]" />
<input type="submit" value="submit" >
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
foreach($_POST['user'] as $key => $value)
{
echo $key." has the value = ". $value."<br>";
}
}
?>
See this in action: http://wistudat.be/try/array.php

username and password help in joomla

What I'm trying to do here is display my login information and once logged in display something else
Example is here
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1){
echo '
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMzM=" name="return">
<input type="hidden" value="1" name="39ea5446d876078c6f6221d396ef5bd4">
</form>
';
}
else
{
echo '
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="994c61f8ab4ccf23fe9dae6546a87089">
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
';
}
?>
No I know what I am doing wrong just have no clue how to fix it. the two
need to have a different generated number each time but how do i do this.
since this numbers are the same every time if i log in then out then try to log back in it will give me "Invalid Token"
When i go into the login template it gives me
this for login
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
and this for log out
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
Now if I replace the hidden fields that already have the pregenerated numbers with the php stuff above when i try to refresh my page it goes completely blank.
I am at a loss with this see as how I am not very advanced in php. any help anyone cant provide would be massively helpful..
why not try like this,
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1):
?>
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<?php else:
?>
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
<?php endif;?>

HTML input field jumps

I have 2 text fields, user and password. When I enter the password, it jumps to the first one. I have no idea why that is happening. I couldn't find why it is jumping. How do I change it so the password form doesn't jump? Here is the code:
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" action="index.php" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form><br />
<form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
?>
You have both of the inputs wrapped in one label. The browser is getting confused and it thinks that that entire content is a label for the first input (that's how labels work, apparently). You should only use <label> to wrap text for input.
This:
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
Should be this:
<input name="user" type="text" id="user">
<label for="user">ID</label><br />
<input name="pass" type="password" id="pass">
<label for="pass">Password</label><br />

Categories