I have a HTML Form that uses partial PHP to grab the value, the form is basically like an edit account details form.
The Problem
I cannot work out why the form is not working and when using notepad++ to edit my code if I click on the it shows the start to be a DIV which just confuses the matter even more... When submitting the form it takes you back to the form page with no message so I am lost for a reason..
Form Page
<form method="POST" action="dev.php">
<!-- Row -->
<div class="row-fluid">
<!-- Column -->
<div class="span6">
<!-- Group -->
<div class="control-group">
<label class="control-label" for="fname">First name</label>
<div class="controls">
<input type="text" name="fname" id="fname" value="<?php echo $user_fname; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="First name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
<!-- Group -->
<div class="control-group">
<label class="control-label" for="lname">Last name</label>
<div class="controls">
<input type="text" name="lname" id="lname" value="<?php echo $user_sname; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="Last name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
</div>
<!-- // Column END -->
<!-- Column -->
<div class="span6">
<!-- Group -->
<div class="control-group">
<label class="control-label" for="email">Email Address</label>
<div class="controls">
<input type="text" name="email" id="email" value="<?php echo $user_email; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="First name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
<!-- Group -->
<div class="control-group">
<label class="control-label" for="phonenumber" >Phone Number:</label>
<div class="controls">
<input type="text" name="phonenumber" id="phonenumber" value="<?php echo $user_number; ?>" class="span10" />
</div>
</div>
<!-- // Group END -->
</div>
<!-- // Column END -->
</div>
<!-- // Row END -->
<div class="separator line bottom"></div>
<!-- Group -->
<div class="control-group row-fluid">
<label class="control-label" for="bio">About me</label>
<div class="controls">
<textarea id="bio" name="bio" class="span12" rows="5"><?php echo $user_bio;?></textarea>
</div>
</div>
<!-- Form actions -->
<div class="form-actions" style="margin: 0;">
<button type="submit" id="accountdetails" name="accountdetails" class="btn btn-icon btn-primary glyphicons circle_ok"><i></i>Save changes</button>
</div>
</div>
</form>
<!-- // Form actions END -->
dev.php
if (isset($_POST['accountdetails'])) {
if (isset($_POST['fname']) || isset($_POST['lname']) || isset($_POST['email']) || isset($_POST['phonenumber']) || isset($_POST['bio'])) {
die ("HERE");
};
};
I probably need to drink more Coffee but I cannot for the life of me work out why it is not working.
Any help would be appreciated!
Thanks in advance.
EDIT
I put the name's in and this did not help, now the URL of the page shows this:
update.php?fname=Aaron&lname=Hatton&email=me%40aaronhatton.co.uk&phonenumber=0123456789&bio=+18+%7C+London+%7C+Taken&accountdetails=
any ideas?
One: do what Fred said (name attributes on your input tags).
Two: You're missing the </form> tag at the end.
Your form page seems correct, however, since the form updates the user data, look what the dev.php code is doing:
isset() function returns true if the value is set and you manual set the fields so it will evaluate to true.
and in your if statement you are ORing all the conditions so as soon as it finds 1 true condition, it will go into the if statement body and execute die which will do nothing.
so if you want to test, instead of using die, try echo "here" to see if a message is printed.
So I found out the form works perfect and there was some AJAX being used by another coder, removed and surprise surprise it works perfectly!
Damn co-workers!
Thanks to all that helped!
Related
I have created a form for something i call a site survey. Before i had the form one one page. But decided to spread it across three html/css tabs. At first it did let me submit to a MySQL db. But I didn't make a backup of a working example with the tabs as it wasn't fully what I wanted yet.
Now it glitches and wont create a new record in the db
Problem
I fill in the first part of the form which works Okay. I click next to send me to the next tab. and go to fill in the rest of the form. I am instantly seeing one of the "please fill out this field" because it is "required" in the code. Once filled, i press the next button again. Which this then takes me to the next tab but then instantly to the first tab and refreshes everything
The next and previous buttons work and dont glitch when there are no answers entered into the fields
I have no idea how to solve the problem. Which is why I'm seeing if anyone can help.
edit
I changed the button to an A tag like the "previous" a tag does. This stops the glitches. However the form does not submit...
Function for the Next/Previous button to work -
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">
$('.next-button').click(function(){
$('.nav-tabs > .active').next('li').find('a').trigger('click');
//trigger the click on the tab same like we click on the tab
});
$('.previous-button').click(function(){
$('.nav-tabs > .active').prev('li').find('a').trigger('click');
//trigger the click on the tab same like we click on the tab
})
</script>
HTML Code -
<div class="row"> <!-- 2 -->
<form class="row g-3" action="<?= $data['action'] ?>" method="post"><!-- 3 -->
<div class="col-sm-12 survey-tabs"> <!-- 4 -->
<ul class="nav nav-tabs" hidden>
<li class="active">Contact & Site Details</li>
<li class="">Questions</li>
<li class="">Site Details</li>
</ul>
<div class="tab-content"><!-- 5 -->
<div class="tab-pane active" id="tab1">
<h1>Contact & Site Details</h1>
<div class="row"> <!-- START TAB ROW 1 -->
<div class="col-md-7">
<label for="site_name" class="form-label">Site Name*</label>
<input type="text"
class="form-control"
id="site_name"
name="site_name"
value="<?= $data['record']['site_name'] ?? '' ?>"
placeholder="Enter Site Name"
required><br>
</div>
<div class="col-md-5">
<label for="poNum" class="form-label">PO Number*</label>
<input type="text"
class="form-control"
id="poNum"
name="poNum"
value="<?= $data['record']['poNum'] ?? '' ?>"
placeholder="Enter PO Num (Given in Email)"
required>
</div>
<div class="tab-control">
<a class="next-button" role="button"><button class="btn btn-primary">Next</button></i></a>
</div>
</div>
<!---------------------------------------------------------------------------------------------------------------------------------------->
<div class="tab-pane" id="tab2">
<h1>Questions</h1>
<div class="row"><!-- START TAB ROW 2 -->
<div class="col-12">
<h6 for="current_machine">1. What is your Current Machine?</h6>
<input type="text"
class="form-control"
id="current_machine"
name="current_machine"
value="<?= $data['record']['current_machine'] ?? '' ?>"
placeholder="Leave blank if none"><br>
</div>
<div class="col-12">
<h6 for="ordered_machine">2. What Machine did you Order?*</h6>
<input type="text"
class="form-control"
id="ordered_machine"
name="ordered_machine"
value="<?= $data['record']['ordered_machine'] ?? '' ?>"
placeholder="Machine(s) Ordered"
required> <br>
</div>
</div> <!-- END TAB ROW 2 -->
<div class="tab-control">
<a class="previous-button" role="button"><i class="fa fa-angle-left fa-3x fa-fw"></i></a>
<a class="next-button" role="button"><button class="btn btn-primary">Next</button></i></a>
</div>
</div>
<!---------------------------------------------------------------------------------------------------------------------------------------->
<div class="tab-pane" id="tab3">
<h1>Site Details</h1>
<div class="row"><!-- START TAB ROW 3 -->
<div class="col-12">
<h6 for="q7">9. What floor is the Machine(s) going to be located on?</h6>
<input type="text"
class="form-control"
id="q7"
name="q7"
value="<?= $data['record']['q7'] ?? '' ?>"
placeholder="Please enter what floor your machine will be located on"> <br><br>
</div>
</div> <!-- END TAB ROW 3 -->
<div class="tab-control">
<a class="previous-button" role="button"><i class="fa fa-angle-left fa-3x fa-fw"></i></a>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary mb-3"><?= $data['button'] ?></button>
</div>
</div>
</div><!-- 5 -->
</div><!-- 4 -->
</form><!-- 3 -->
</div> <!-- 2 -->
</div><!-- 1 -->
So the problem is that i have a input type number just like any other regular input type number, but for some reason that am not able to understand it put a "<" sign in front of my numbers.
<div class="child">
<div class="label-form">
<label for="numC">Numero de Contrato:</label>
</div>
<?php while($vector2=mysqli_fetch_array($resultado2)) { ?>
<div class="input">
<?php echo $vector2[0]+1;?>
<input type="hidden" name="NumeroContrato" value="<?php echo $vector2[0]+1;?>">
</div>
</div>
<?php } ?>
<div class="child">
<div class="label-form">
<label for="nMota">Numero da mota</label>
</div>
<div class="input">
<input type="number" id="nMota" name="nMota" placeholder="Bike Number" required>
</div>
</div>
Its the "nMota" input; for example if i put a 1 it receive the information as <1 if i put a 7 it put <7. I have no idea why.
I am having trouble to post a html form. I am posting one form and getting the post value to my variable and then I am post this form but this form is not posting.
HTML code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" autocomplete="off">
<div class="widget-box">
<div class="widget-title"> <span class="icon"> <i class="icon-user"></i> </span>
<h5>Amc details</h5>
</div>
<div class="widget-content">
<div class="controls controls-row">
<div class="control-group span3">
<label for="normal" class="control-label">Installation Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-ins-date" data-date="01-02-2016" name="amc-ins-date" data-date-format="dd-mm-yyyy" class="datepicker span12" placeholder="Enter installation date">
</div>
</div>
<div class="control-group span3">
<label for="normal" class="control-label">Start Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-start-date" data-date="01-02-2016" name="amc-start-date" data-date-format="dd-mm-yyyy" placeholder="Enter amc start date" class="datepicker span12 ins-date">
</div>
</div>
<div class="control-group span3">
<label class="control-label">End Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-end-date" data-date="01-02-2016" name="amc-end-date" data-date-format="dd-mm-yyyy" placeholder="Enter amc end date" class="datepicker span12 ins-date">
</div>
</div>
<div class="control-group span3">
<label class="control-label">Amount<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-amount" name="amc-amount" class="span12" placeholder="Enter amc amount">
</div>
</div>
</div>
</div>
<div class="form-actions">
<input style="float:right" type="submit" name="amc-installation" class="btn btn-success" value="Save">
</div>
</form>
PHP code:
// i have submitted a form here and its posted
// installation details
$mc_serial = $_POST['mc-serial'];
$mc_model = $_POST['mc-model'];
$contract_type = $_POST['contract_type'];
$no_of_copies = $_POST['no-of-copies'];
$spare_part = join(",",$_POST['spare-part']);
$eng_name = $_POST['eng-name'];
$review = $_POST['review'];
// check if the machine already exits
if(IsMachine($mc_serial,$con)){
echo msgIsMachine();
exit();
}
if($contract_type == 'AMC'){
require './forms/amc.php'; // this is the html i have shown above
} elseif ($contract_type == 'ASC') {
require './forms/asc.php';
} elseif ($contract_type == '4C') {
require './forms/4c.php';
} elseif ($contract_type == 'RENTAL') {
require './forms/rental.php';
} elseif ($contract_type == 'WARRANTY') {
require './forms/warranty.php';
}
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);($_POST);
}
The output of var_dump is NULL. I don't get any problem.
You echo the second form (during the script which responds to the submission of the first one), but then immediately check for values returned from it within the same script execution. You have to wait for the user to post the form back before you can check the submitted values. This would be a separate postback, and therefore a separate execution context for the PHP.
So the code to check the values from the second form needs to be in a separate section (or file) which is triggered by the submission of the second form.
There's no $POST in PHP you should use $_POST instead :
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);
}
NOTE : You should place the var_dump($_POST); inside the if statement, so it will be trrigered just after the submit.
Hope this helps.
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);
}
You should use $_POST not $POST.
Hope this will helps you :)
I'm doing a e-commerce admin panel and I need a quick script for inserting data into MySQL. Here's what i've done and it does nothing.
<form action="#" id="form_sample_1" class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label">Package Name<span class="required">*</span></label>
<div class="controls">
<input type="text" name="pkg_name" data-required="1" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Package Price <span class="required">*</span><small>(In Dollars)</small></label>
<div class="controls">
<input name="pkg_price" type="number" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Package Contains</label>
<div class="controls">
<input name="pkg_contains" type="text" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Your Password</label>
<div class="controls">
<input name="sifre" type="password" class="span6 " value=""/>
</div>
</div>
<div class="form-actions">
<button type="button"name="btn" class="btn btn-primary">Send request to server.</button>
</div>
</form>
<!-- END FORM-->
</div> <!--widget box light-grey end-->
<!-- Mass PHP starts here! -->
<?php
echo mysql_error();
include("include/baglan.php");
// set posts here.
$_POST['pkg_name'] = $pkg_name;
$_POST['pkg_price'] = $pkg_price;
$_POST['pkg_contains'] = $pkg_contains;
$sifre = mysql_real_escape_string(md5($_POST['sifre']));
if($_POST['btn'] and $_POST["sifre"] = $sifre){
mysql_query("INSERT INTO packages (pkg_name, pkg_price,pkg_contains) VALUES $pkg_name $pkg_price $pkg_contains");
echo "Success.";
}
else {
echo mysql_error();}
It returns nothing! I've re-written all code but nothing! please help me. The databae variables are;
id, auto incerment
pkg_name text
pkg_price int
pkg_contains mediumtext
Assign variable name should be the left side.
// set posts here.
$pkg_name=$_POST['pkg_name'];
$pkg_price=$_POST['pkg_price'];
$pkg_contains=$_POST['pkg_contains'];
Values() is function, put all vars in bracket and split them with ','.
mysql_query("INSERT INTO packages (pkg_name, pkg_price,pkg_contains) VALUES($pkg_name,$pkg_price,$pkg_contains)");
I'm currently encountering a problem which is baffling me. There will be a lack of PHP mixed with HTML due to using a MVC Framework.
What i've got:
Form A on Page 1 with a submit button which directs user input from Form A to page 2 with a chunk of text for the user to read before continuing, a hidden text field which will contain a serialized array from Form A and a submit button to continue to the validation of user input.
My forms direct to the correct pages as required, the post array can be seralized providing I do not put it into a text field. The HTML from form A follows:
<form action="/RegisterInformation" method="POST">
<div class="row">
<div class="large-12 columns">
<input type="text" name="Username" placeholder="Username, ex: JohnDoe ">
</div>
</div>
<div class="row">
<div class="large-4 columns">
<input type="password" name="Password" placeholder="Password">
</div>
<div class="large-4 columns">
<input type="password" name="cpassword" placeholder="Confirm Password">
</div>
<div class="large-4 columns">
<input type="text" name="email" placeholder="Email, ex: JohnDoe#provider.com">
</div>
</div>
<div class="row">
<div class="large-12 columns">
<textarea name="Referral" placeholder="Where Did You Hear About Us?"></textarea>
</div>
</div>
<div class="row">
<div class="large-4 columns">
<input type="submit" name="submit" value="Continue" class="button">
</div>
</div>
</form>
The redirect to page 2:
<div class="row">
<div class=" large-12 columns">
<p>
<?php echo $data['PreregisterInformation']; ?>
</p>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<form action="/Continue" method="POST">
<input type="text" name="SubmitInfo" value="<?php echo serialize($_POST); ?>">
<input type="submit" name="submit" value="Continue" class="button">
</form>
</div>
</div>
With the current example, i've got the text field set to being visible, so I can see what's going on.. But this is where it gets strange.
What i'm getting is two different types of results.
The first, is that when I echo the serialized array outside a input field. I get the desired results:
a:6:{s:8:"Username";s:1:"s";s:8:"Password";s:1:"4";s:9:"cpassword";s:1:"4";s:5:"email";s:3:"asd";s:8:"Referral";s:3:"asd";s:6:"submit";s:8:"Continue";}
The second is when I use the following:
<input type="text" name="SubmitInfo" value="<?php echo serialize($_POST); ?>">
Which passes an invalid serialized array to page 3 breaking the whole process.
I assume it's not a HTML related error, but the new line break in the serialized array definition a:6. I have made an attempt to rectify this problem by removing the new line break with str_replace:
$Ser = serialize($_POST);
$Ser = nl2br($Ser);
$Ser = str_replace("<br>","00",$Ser);
echo $Ser;
which has proven not to work.
This is not a direct solution of your problem, but have you tried json_encode or avoiding the hidden field by storing the date into $_SESSION?