I'm making a system where a user can search through a library by specific fields.
I currently have a PHP document called index.php that contains a drop down box, a text box, and a submit button. The user selects from the drop down box which field they want to search through (for example Author or Title), then enters their search criteria in the text box (for example "Tolkien" or "The Hobbit") and then clicks on the submit button which then loads simpleSearch.php. The text the user searches for and the field they are searching through are defined on simpleSearch.php as follows:
$queryString = $_GET["userSearch"]; // get user's search string
$queryType = $_GET["searchType"]; // get user's search type
What I would like to have is a different layout but the same functionality on the index.php page. The layout above the double blue line is the current layout. The layout below the double blue line is my desired layout.
Instead of choosing a field from the drop down box and clicking on Submit the user would enter their search criteria and then click on one of the fields. The button would act as the drop down selector AND the submit button at the same time.
Here is my code for the current layout:
<form action="simpleSearch.php" method="get">
<select name="searchType">
<option value="all">All Fields</option>
<option value="author">Author</option>
<option value="title">Title</option>
<option value="subject">Subject</option>
</select>
<input type="text" name="userSearch">
<input type="submit">
</form>
Any help at all would be really appreciated! Thanks!
what about use:
<form action='simpleSearch.php' method='get'>
<input type="text">
<input type="submit" value="all" name="userSearch">
<input type="submit" value="author" name="userSearch">
<input type="submit" value="title" name="userSearch">
<input type="submit" value="subject" name="userSearch">
</form>
And in simpleSearch.php u can get value by $_GET['userSearch']
and dont forget to SQL inject danger ;)
Related
When I try to read the dropdown with $data['fieldname'] , I expect to get back the text that’s displayed in the field, but that isn’t what happens. Dropdowns always point to either another record instance or an element of a list; these instances and elements all have an internal ID, and that internal ID is what I get back.
But what if I actually want the text that’s displayed in the dropdown?
When submitting a form, what you get is just the value of the selected option, and not the text. However, there is a way to bypass it if you really need the text. The strategy is to add a hidden input to your form, and fill it with the text of the selected option whenever a new option is selected. It will be something like the following code:
<form action="somewhere.php" method="POST">
<select name="field" id="field" onchange="document.getElementById('content1').value=this.options[this.selectedIndex].text]">
<option value="1">First Value</option>
<option value="2">Second Value</option>
</select>
<input type="hidden" name="fieldname" id="content1" value="" />
<input type="submit" name="submit" value="submit">
</form>
Explanation: here we have a dropdown named field, and there is an onchange event for this dropdown. Whenever a new option is selected, we put the text of that option into the hidden input which is called content1. The name of this hidden input is fieldname, so when this form is submitted, you can get the text in the post variable: $_POST['fieldname'];
Basically, I have two form, a UserForm and AdminForm.
On the AdminForm, I want to have a text field in which the admin can type in a new charity and then that new charity will be added to the UserForm charity_list as a new value, though I am not sure how to that and it is the last part of my code.
This is where i want to add the the radio button on the userForm:
<font size ="5" >Pick Your Charity</font>
<br><br>
<input type ="radio" id="1" value="1" name="charity_list">Street2Feet
<br>
<input type ="radio" id="2" value="2" name="charity_list">The Good Project
here is where i was trying to do it on admin form:
<form method="post" action = "UserForm.php" >
<input type="submit" name="Insert" value="Add New Charity">
Can someone please help? if there is too much information, let me know
Basically, what you're trying to do is the Admin Form act as simple CMS where the admin can add the Charity List and display it in the User Form.
Here what you should you do.
1) Save the value of charity added by admin in the database
2)Pull the list from database and display it in the User form (dynamically)
i would like to make form for uploading multiple data with HTML and PHP into database (if needed i can use JS aswell). I want user to be able to fill in post name, add image (or more) and some text.
I found a lot of info how to make multiple input (for example: 3 pictures with 1 submit button) but i didnt find anything about how can i do what i want.
The reason can be my english skills as i believe im unable to ask google the right question.
I would really appreciate any info, even if it's only the right wordt to put on google or some online blog/tutorial on how to do it.
(if i wasnt clear enough, i can add picture of what i want to make)
HTML form:
Title: <input type="text" name="title"><br>
Category (you can select more): <select name="category" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select> <br>
Description:<textarea rows="4" cols="50"> Add your description here. </textarea> <br>
Image(s): <input type="file" name="images" accept="image/*">
<br>
<input type="submit" value="Submit">
I'm using this following simplified HTML code integrated in a PHP code, which is left out.
The user can choose between two options of the dropdown selection and then enters an input to be submitted.
The problem is that whenever clicking on the submit button after an input is entered and option2 is selected, then the dropdown selection is changed back to option1.
Now, I want option1 to be the default when the page is first loaded, but I'd also like that whenever option2 is selected - that it would be "anchored", that is it wouldn't be changed unless the user selects a different option or when the page is refreshed....
Does anybody know how to do that?
Thanks in advance!
P.S - don't know if this matters but in the original code, I entered the PHP file name in the "action" attribute inside the form tag.
<html>
<head>
</head>
<body>
<form action="" method="post" >
Category:
<select id="searchType" name="searchType" size="1">
<option value="1" class="bold-option">
Option1
</option>
<option value="2">Option2</option>
</select>
<br/>
<input type="text" name="name" class="input_field" id="input_txt" dir="auto" >
<input type="submit" value = "submit!" class="submit_button"/>
</form>
</body>
</html>
I've been looking around on SO and I don't -think- this is something that's up here, either that or it's something I've missed. If so, please point me there and I'll simply mark this question as answered.
I have a completely working PHP form where my users input information into input boxes and there's a button at the bottom that submits the information to the MySQL database, so that part works perfectly. What I'm trying to do now is this: have 2 drop down menu's, each one with a static list of choices and I'd like those choices to also get sent to the database.
For instance, currently in my form I have First Name (frame) and Last Name (lname) that the user can input and then if I query the database it spits out First Name and Last Name perfectly. So now I'd like to add to my form a drop down box where the user can pick, for example, Boy or Girl, and then after doing that click the submit button that's already there (I don't want the drop-down to submit the data, and I don't want the drop-down to be populated from the database.)
I'm guessing I need to use Javascript for this part? But I really don't know.
Any advice would be appreciated.
<html>
<head>
<title>MyForm</title>
</head>
<body>
<form id="form" name="form" action="" method="post">
<Label>First Name/Organization</label>
<input type="text" name="firstname" value="<?php echo $firstname; ?>"/>
<input type="submit" name="submit" value="Add entry">
</form>
</body>
</html>
So, as part of the same form, you simply treat it just like the input boxes. Here's an example:
If the dropdown is named:
<select name="gender">
<option value="boy">Boy</option>
<option value="girl">Girl</option>
</select>
Then in your php, you would simply get the value for gender:
$gender = $_POST["gender"];
And add to your SQL statement where you are saving the first/last name the additional field and value for gender.
Of course, you would have to first modify the table to have the column for gender....
Hope that helps!
It sound s like you just want a simple html drop down as part if your form. Just use
<select name = 'gender'>
<option value = 'boy'> Boy </option>
< option value = 'girl'> Girl </option>
</select>
Then access $_POST['gender'] in the receiving script to put it into the database (after validation of course)