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 -->
Related
My submit button suddenly stopped working. It submits data into a MySQL database.
While I was doing some design changes, it suddenly stopped working.
Are there any apparent errors/mistakes in the code below?
I'm a noob who's currently trying to learn some PHP and so on, so any help would be much appreciated. :)
<section id="moviesearch">
<!-- Section -->
<div class="subcribe2">
<div class="container">
<!-- Container -->
<div class="row">
<!-- Row -->
<div class="col-md-4">
</div>
<body ng-app="myApp">
<div ng-controller="MyCtrl" class="col-md-4">
<form class="form-watch-list-create">
<input required="required" placeholder="Movie title" type="text" class="form-control" typeahead="item.Title for item in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-min-length="2" typeahead-wait-ms="1000" typeahead-on-select="onSelected($item)"
typeahead-template-url="customTemplate.html" ng-model="asyncSelected">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-sm btn-dark">Add to watchlist</button>
</div>
</body>
</div>
<!-- End Row -->
</div>
<!-- End Container -->
</div>
<script type="text/ng-template" id="customTemplate.html">
<a>
<span bind-html-unsafe="match.label | typeaheadHighlight:query" style="width: auto;"></span>
({{match.model.Year}})
<!-- <img ng-src="{{match.model.Poster}}" width="120"> -->
</a>
</script>
<div ng-controller="MyCtrl">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
</section>
Edit
Here's the code that sends data into the MYSQL database:
function addWatchList() {
if (isset($_GET['addtowatchlist'])) {
$name = $_GET['name'];
$conn = dbmysql();
$query ="INSERT INTO watch_list values(null,'{$name}','{$_SESSION['user_id']}','NOW()')";
if (mysqli_query($conn,$query)) {
$last = "SELECT * FROM watch_list WHERE created_by = '{$_SESSION['user_id']}' order by id desc limit 1";
$data = mysqli_query($conn,$last);
while ($row = mysqli_fetch_assoc($data)) {
include "_view.php";
}
}else {
echo "An error occurred. Please try again.";
}
exit;
}
}
I am looking to your code, missing attribute action="somefile.php" and method="get" if you are planning on submitting it using the form, you should put it or if you are planning on submitting your code using javascript you can use <form onsubmit="myFunction()"> That is what you are missing. I am not seeing you addtowatchlist name from your input so that php can catch it to your isset.
The submit button isn't inside the form.
You're missing the </form> tag to end the <form>. But you have </div> that matches the <div> just before </form>, so it's implicitly closing the <form> tag as well. Then you have <input type="submit"> after it. Since the submit button isn't inside the form, and has no form tag associating it with the form, it doesn't know which form it should submit when you click on it.
Try this:
<form class="form-watch-list-create">
<div ng-controller="MyCtrl" class="col-md-4">
<input
required="required"
placeholder="Movie title"
type="text"
class="form-control"
typeahead="item.Title for item in getLocation($viewValue)"
typeahead-loading="loadingLocations"
typeahead-min-length="2"
typeahead-wait-ms="1000"
typeahead-on-select="onSelected($item)"
typeahead-template-url="customTemplate.html"
ng-model="asyncSelected">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-sm btn-dark">Add to watchlist</button>
</div>
</form>
This puts the form around both columns.
Use the method attribute in form tag and end the form tag properly
<form role="form" method="get" class="form-watch-list-create">
<div ng-controller="MyCtrl" class="col-md-4">
<input
required="required"
placeholder="Movie title"
type="text"
class="form-control"
typeahead="item.Title for item in getLocation($viewValue)"
typeahead-loading="loadingLocations"
typeahead-min-length="2"
typeahead-wait-ms="1000"
typeahead-on-select="onSelected($item)"
typeahead-template-url="customTemplate.html"
ng-model="asyncSelected">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-sm btn-dark">Add to watchlist</button>
</div>
</form>
I've recently completed a simple login form with php and mysql.
Now I am heading onto the styling part which I am not too familiar with.
Login form code:
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<form action="" method="post">
<div class="form-group has-feedback"><input class="form-control"
name="user_key" placeholder="XXXX-XXXX-XXXX-XXXX" type="text" /></div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck"><label><input type="checkbox" /> Remember Me
</label></div></div>
<!-- /.col -->
<div class="col-xs-4"><button class="btn btn-primary btn-block btn-flat"
name="submit" type="submit">Sign In</button></div>
<!-- /.col --></div>
</form>
Login form screenshot:
http://prntscr.com/afrajr
I was thinking maybe echoing it to display an outline around the box which is red when their is no valid key in the mysql table but i'm not sure how to.
My form fields have space in them, if I select and delete this space my prefilled text shows back up. I don't know what to make of this and have been trouble shooting all day. Any ideas? Here is my code...
<?php
include '_include/php/header.php';
#set variables to be used in the header
$page_title = "Assesment";
?>
<div class="page" id="subheader">
<div class="container">
<!-- Title Page -->
<div class="row">
<div class="span12">
<div class="title-page">
<h2 class="title">Four simple steps...</h2>
<h3 class="title-description">To dictate what you need
in a website</h3>
</div>
</div>
</div><!-- End Title Page -->
<!-- submenu -->
<?php
include '_include/php/submenu.php'; ?>
</div>
</div><!-- End sub header -->
<!-- main Section -->
<div class="page" id="contact">
<div class="container">
<!-- Title Page -->
<div class="row">
<div class="span12">
<div class="title-page">
<h2 class="title">Assesment - Step One</h2>
<h3 class="title-description">Status: <span class=
"color-text"><?php echo $assessresult; ?></span></h3>
</div>
</div>
</div><!-- End Title Page -->
<!-- main Form -->
<div class="row">
<div class="span9">
<form action="assessment_submitted.php" class="contact-form" id="contact-form"
method="post" name="contact-form">
<h3 class="color-text">What do you wish to get out of
your website?</h3>
<p class="contact-message">
<textarea required cols="10" id="client-goals" name=
"client-goals" placeholder=
"What do you wish to acheive by having a website? ie. creating a web presence, expanding sales by creating an online market, networking, ect."
rows="5">
</textarea></p>
<h3 class="color-text">What key fatures are you looking
for?</h3>
<p class="contact-message">
<textarea required cols="10" id="client-needs" name=
"client-needs" placeholder=
"What key features are you looking to have within your website? ie. storefront, social media intigrtion, a blogging platform, content managment system, ect."
rows="5">
</textarea></p>
<script type = "text/javascript" >
var i = 1;
function addUrl() {
if (i < 3) {
i++;
var p = document.createElement('p');
p.innerHTML =
'<hr><textarea required id="client-needs" placeholder="Add URL #' + i +
'" name="example' + i +
'" rows="1" cols="10"><\/textarea><input type="button" value="Remove added URL" onclick="removeUrl(this)">';
document.getElementById('example').appendChild(p);
} //END if
} //END addUrl function
function removeUrl(textarea) {
textarea.parentNode.parentNode.removeChild(textarea.parentNode);
i--;
} //END removeUrl function
</script>
<h3 class="color-text">Do you have and examples of what
you want?</h3>
<p class="contact-message" id="example">
<textarea cols="10" id="examples" name="example1"
placeholder="Do you know of any website like the one you want? ie. google.com, p5services.com, youtube.com"
rows="1">
</textarea></p><br>
<input onclick="addUrl()" type="button" value=
"Add url example">
<h3 class="color-text">Do you have a budget in
mind?</h3>
<p class="contact-message">
<textarea required cols="10" id="client-budget" name=
"client-budget" placeholder=
"Enter a budget, approximate or exact. This will help us decide if the scope of your project is in line with what you are interested in spending"
rows="2">
</textarea></p>
<h3 class="color-text">Do you have a timeline or
deadline?</h3>
<p class="contact-message">
<!-- <textarea id="client-deadline" placeholder="When do you need this done by?" name="client-deadline" rows="2" cols="10"></textarea> -->
<!-- <input id="client-deadline" name="client-deadline"
type="date"></p> -->
<!-- add a call to action for further services later -->
<h3 class="color-text">Any other comments?</h3>
<p class="contact-message">
<textarea cols="10" id="client-comments" name=
"client-comments" placeholder=
"Don't let us over look anything!" rows="5">
</textarea></p>
<p class="contact-submit"><input name=
"submit_assessment" type="submit" value=
"Save New Record"></p>
<div id="response"></div>
</form>
</div>
<div class="span3">
<div class="contact-details">
<h3><span class="font-icon-info"></span> Assesment
Objective</h3>
<p>The assesment section is used to define your needs
and help us decided what tool we need to impliment in
order to help you reach your goals</p>
<h4 class="color-text">After submitting this you will
recive a quote!</h4>
</div>
</div>
</div><!-- End main Form -->
</div>
</div><!-- End main Section -->
<?php
include '_include/php/footer.php'; ?>
The textarea element takes placeholder text in a different form. You need to put it between the tags like so:
<textarea>My text area placeholder text goes here</textarea>
The space that you are seeing then deleting to see your placeholder is caused by the line break between your opening and closing textarea tags
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!
I have some portlets here that has an ID for each of it. What I'm trying to do is to pass these IDs to a popup modal after pressing an Add button in the portlet.
Here is the portlet view:
#foreach($portlets as $portlet)
<div class="box span4">
<div class="box-header well" data-original-title>
<h2><i class="icon-th"></i> {{$portlet->portlet_title}} </h2>
</div>
<div class="box-content">
<div class="row-fluid">
// some contents over here
</div>
<div class="box-icon">
<i class="icon-plus-sign"></i>
</div>
</div>
</div>
#endforeach
Notice the Add New Link button at the bottom of the code, when I press that, a modal will appear. Here is the view of it:
<div class="modal hide fade" id="linkSettings">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Add New Link</h3>
</div>
<form method="post" action="{{ URL::to('addlink') }}" >
<div class="modal-body">
<div class="control-group">
<label class="control-label" for="focusedInput">Link Title:</label>
<div class="controls">
<input class="input-xlarge focused" id="link_title" name="link_title" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="focusedInput">Add A Link:</label>
<div class="controls">
<input class="input-xlarge focused" id="link_url" name="link_url" placeholder="eg. http://www.example.com/" type="text">
</div>
</div>
</div>
<div class="modal-footer">
Close
<input type="submit" id="submit" name="submit" value="Submit" class="btn btn-primary">
</div>
</form>
</div>
This modal has a form in it to be processed in the controller. But how do I send the portlet ID to this modal so that it can be stored in the database during processing in the controller? Because I want it to automatically know what portlet I want to add links in it. Any idea?
If anything, please let me know.
You could attach a jQuery event handler to clicking the "Add New Link" button, and use it to populate a hidden field in the modal view.
i.e. something like:
$("a.new_link").click(function(){
portlet_id = $(this).parent().parent().attr("id");
$("div.modal form input.my_hidden_field").val(portlet_id)
});
And somewhere in the <form> for the modal:
<input type="hidden" name="portlet_id" class="my_hidden_field"/>
Then, you just need to get the portlet_id POST parameter with Laravel/PHP to determine the portlet ID that was used.
Edit
Revised handler based on the code you gave:
$('.btn-settingLink').click(function(e){
e.preventDefault();
$('#linkSettings').modal('show');
// get the portlet_id and modify the midden field
portlet_id = $(this).parent().parent().attr("id");
$("div.modal form input.my_hidden_field").val(portlet_id)
});