Submit button not searching - php

I' trying to create a search box. If you type and hit enter, it searches and works. However, I'm trying to get a button to work so that when it is clicked it searches. I'm having trouble trying to achieve this as nothing is happening when the img is clicked.
This is the code:
<div class="large-8 small-9 columns">
<form action='search.php?' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</form>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name='query' type="submit">
<img src="img/icon/Search.png" class="search-button" alt=""/>
</button>
</div>

to get hte button to submit the form - it has to ither be in the form or alternatively trigger a function that submits the form. Note that you do not need the "?" at the end of the action url - the GET method will add it when the query string is appended to the URL. You could also do this with a keyup event and via ajax- have a live search based on the value of the typed input.
<div class="large-8 small-9 columns">
<form action='search.php' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name='query' type="submit">
<img src="img/icon/Search.png" class="search-button" alt=""/>
</button>
</div>
</form>
if you want to have it oustide of the form you can create an onclick event that will then trigger the form submission (note the use of jQuery for this action) - and you would normally have this in the JS as a separated onclick handler raher than in the html code.
<div class="large-8 small-9 columns">
<form action='search.php' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</form>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name="query" onclick="$('[name=query]').submit()">
<img src="img/icon/Search.png" class="search-button" alt=""/> </button>
</div>

You need to place the button within the <form> tags. This will trigger the <button> to submit the form according to the specified form action. Otherwise, the <button> will not be considered part of the form, this it's not submitted.
<div class="large-8 small-9 columns">
<form action='search.php?' method='GET' name='query' >
<input type='text' placeholder="Search Waves" id="searchbox" name='query'>
</div>
<div class="large-4 small-3 columns">
<button id="search-button" name='query' type="submit">
<img src="img/icon/Search.png" class="search-button" alt=""/>
</button>
</form>
</div>

Related

HTML form, prevent refresh after clicking submit

I need to prevent refreshing the page after clicking on submit button. I've tried methods like
$("#prospects_form").submit(function(e) {
e.preventDefault();
and "onsubmit="return false" or "type=button"....but the problem is, even though all of these methods work, it seems that my php script doesn't get executed
this is my form
<form method="POST" action="storeImage.php">
<div class="row">
<div class="col-md-6" id="the_cam">
<div id="my_camera"></div>
<div id="start_webcam">
<input style="font-size:13px" type=button class="btn-get-started" value="Start webcam" onClick="start_webcam()">
</div>
<br />
<div id="take_snapshot" style="visibility: hidden;">
<input class="btn-get-started" type=button value="Take Snapshot" onClick="take_snapshot()">
</div>
<input type="hidden" name="image" class="image-tag">
</div>
<div class="col-md-6">
<div id="results" style="text-align: center;"></div>
<br />
<div id="submit" style="visibility: hidden; margin-top:60px;">
<button class="btn-get-started" onclick="submit_image()">Submit</button>
</div>
</div>
</div>

Submit button is not working in my form

This is my form. When I click save, vales are not getting posted and redirected to note.php page.
<form method="post" action="note.php" enctype="multipart/form-data">
<div class="form-group">
<div class="col-sm-1 padding">
<label>Title :</label>
</div>
<div class="col-sm-11 padding">
<input type="text" class="form-control select2-offscreen form-text" name="title" required autocomplete="off" placeholder="Note Heading" tabindex="-1">
</div>
</div>
<div class="toolbar-btns">
<div class="file-attach">
<div class="form-group">
<input type="file" name="file[]" multiple="multiple">
</div>
</div>
<div class="form-group">
<button type="submit" class="btn send-btn" name="btn-note-save">Save</button>
<input type="reset" style="background-color:#417fb9; color:#fff;" class="btn btn-default" id="submitForm" value="Clear"></input>
</div>
</div>
</form>
I think your problem is in note.php. Please use the code below to get the posted values.
<?php
$title=($_POST['title']);
echo $title;
$pic = $_FILES["file"]["name"];
$folder = "../images/users/";
move_uploaded_file($_FILES['file']["tmp_name"], "$folder".$pic);
?>

Form not posting Button name/value

<form action="actions/add_cat.php" method="post" id="rtf" name="">
<input type="text" name="cat_title" id="cat_title" required="required" placeholder="Category Title"/>
<br /><br />
<button type="button" onclick="button_click('#d31b26');" value="d31b26" name="cat_color"><div class="redSelect"></div></button>
<button type="button" onclick="button_click('#f9c04c');" name="cat_color" value="#f9c04c"><div class="yellowSelect"></div></button>
<button type="button" onclick="button_click('#72bce9');" name="cat_color" value="#72bce9"><div class="blueSelect"></div></button>
<button type="button" onclick="button_click('#ec9292');" name="cat_color" value="#ec9292"><div class="pinkSelect"></div></button>
<button type="button" onclick="button_click('#b7d04e');" name="cat_color" value="#b7d04e"><div class="greenSelect"></div></button>
<div class="indexBox">
<div class="indexBoxHeader" id="box">
<i class="fa fa-question-circle" style="font-size: 2em;"></i></div>
<div class="indexBoxFooter">
<div class='printchatbox' id='printchatbox'></div>
</div>
</div>
<br><br>
<input onclick="formsubmit()" type="submit" value="Create Category" name="submit"/>
</form>
If i test using a text input and using the cat_color name it will post that entry but when using the above it does not seem to to take the item I am selecting?
Here is the post query incase you need to see it:
$sql = "INSERT INTO cat_list (cat_title, cat_color) VALUES ('".$_POST["cat_title"]."', '".$_POST["cat_color"]."')";
As I can't comment.
Try to have <radio> buttons instead of normal buttons. So the php/form would understand it is and option.
Example:
<form .. >
..
<input type="radio" name="cat_color" value="#d31b26"><div class="redSelect"></div><br>
<input type="radio" name="cat_color" value="#f9c04c"><div class="yellowSelect"></div><br>
..
</form>
EDIT
<form action="actions/add_cat.php" method="post" id="rtf" name="">
<input type="text" name="cat_title" id="cat_title" required="required" placeholder="Category Title"/>
<br /><br />
<!-- Radio Buttons With customized color class -->
<input type="radio" name="cat_color" value="#d31b26" class="redSelect"><br>
<input type="radio" name="cat_color" value="#f9c04c" class="yellowSelect"><br>
<input type="radio" name="cat_color" value="#72bce9" class="blueSelect"><br>
<input type="radio" name="cat_color" value="#ec9292" class="yellowSelect"><br>
<input type="radio" name="cat_color" value="#b7d04e" class="greenSelect"><br>
<div class="indexBox">
<div class="indexBoxHeader" id="box">
<i class="fa fa-question-circle" style="font-size: 2em;"></i></div>
<div class="indexBoxFooter">
<div class='printchatbox' id='printchatbox'></div>
</div>
</div>
<br><br>
<input onclick="formsubmit()" type="submit" value="Create Category" name="submit"/>
</form>
So in the in the end I just wrapped a hidden field inside the div for my colour picker like so:
<div class="redSelect" onclick="button_click('#d31b26');"><input type="hidden" name="cat_color" value="#f9c04c" ></div>
<div class="yellowSelect" onclick="button_click('#f9c04c');" ><input type="hidden" name="cat_color" value="#f9c04c" ></div>
<div class="blueSelect" onclick="button_click('#72bce9');"><input type="hidden" name="cat_color" value="#72bce9" ></div>
<div class="pinkSelect" onclick="button_click('#ec9292');"><input type="hidden" name="cat_color" value="#ec9292"></div>
<div class="greenSelect" onclick="button_click('#b7d04e');"><input type="hidden" name="cat_color" value="#b7d04e" ></div>
works a treat and posts out the value of the hidden field
With me, happened that my form had so so many inputs that it simply didn't send the last ones (the button and some others). In some way, there is a "limit" on how much data you may send by POST.
Then, I put a hidden input in the upper part of the form with the same name of button and it worked 👍🏻.

Multiple input elements for PHP post form

I've got 3 different stages to my application form and have 2 buttons using the <input type="button"> but when submitting the form, using the last button, it'll only save the third part of the application, how do I get the previous 2 parts form elements?!
<form action="" method="post">
<section class="mainSection">
<section class="firstStep">
<header class="firstStepheader">
Step 1: Your Details
</header>
<section class="firstStepDetails">
<div class="left">
<h1>First Name:</h1>
<input name="firstName" id="firstName" tabindex="1">
<h2 id="fNameError">Please enter your first name</h2>
<h1>Email Address:</h1>
<input name="emailAddress" id="emailAddress" tabindex="3">
<h2 id="emailError">Please enter your email address</h2>
</div>
<div class="right">
<h1>Surname:</h1>
<input name="surName" id="surName" text="" tabindex="2">
<h2 id="sNameError">Please enter your surname</h2>
</div>
<input class="nextButton" id="firstNextButton" value="Next >" type="button">
</section>
</section>
<br>
<section class="secondStep">
<header class="secondStepheader">
Step 2: More Details
</header>
<section class="secondStepDetails">
<div class="left">
<h1>Telephone Number</h1>
<input name="telNo" text="" id="telNo" tabindex="1">
<h2 id="telNoError">Please enter your telephone number</h2>
<h1>Gender</h1>
<select id="gender" tabindex="3">
<option id="male">Male</option>
<option id="female">Female</option>
</select>
</div>
<div class="right">
<h1>Date of Birth</h1>
<input name="dOB" text="" id="dOB" tabindex="2"><h3>Format: DD/MM/YYYY</h3>
<h2 id="dOBError">Please enter a valid date</h2>
</div>
<input class="nextButton" id="secondNextButton" value="Next >" type="button">
</section>
</section>
<br>
<section class="thirdStep">
<header class="thirdStepheader">
Step 3: Comments Section
</header>
<section class="thirdStepDetails">
<div class="left">
<h1>Comments</h1>
<textarea name="telNo" text="" cols="50"></textarea>
</div>
<button class="nextButton" id="submitButton" type="submit">Submit ></button>
</section>
</section>
</section>
</form>
If you want multiple buttons, you'll need to use AJAX to process the form in multiple parts. Otherwise, just use one button at the end. The last button will send everything via $_POST and you can capture it and process it however you want.
Found out that I disabled the inputs in my JQuery meaning the elements wouldn't be posted.

How to convert this form in zend form

I've this HTML form, I need to write it in zend form.
I tried but failed
< form id="form" method="post" class="form">
<fieldset>
<div class="widget">
<div class="title"><img src="images/icons/dark/list.png" alt="" class="titleIcon" /><h6>Add new section</h6></div>
<div class="formRow">
<label>Section name:</label>
<div class="formRight">
<input type="text" name="cat_name" id="cat_name" value="" />
<input name="art_author" id="art_author" type="hidden" value="admin" />
</div>
<div class="clear"></div>
</div>
<div class="formSubmit">
<input type="submit" value="Add" class="redB" />
<input type="reset" value="Reset" class="brownB" />
</div>
<div class="clear"></div>
</div>
</fieldset>
Can any body help me please?
First step http://framework.zend.com/manual/1.12/en/learning.quickstart.intro.html
Second step http://framework.zend.com/manual/1.12/en/zend.form.html
And do not make copy paste. Try to make your zend_form work using Zend Manual.
Good luck!

Categories