I am currently making a website where they can create their own pages and the areas where they put their information are in their own boxes. Each box is a row on my server. I want them to be able to have as many of these boxes as they want. So before I have changed the website the form looked like this
<form method="GET" action="createpage.php">
<input type="text" name="titleOne">
<input type="text" name="paraOne">
<input type="text" name="titleTwo">
<input type="text" name="paraTwo">
<button type="submit" name="button">button</button>
</form>
It also has the ability to be an image but that doesn't make a difference to what I am hoping you will help me figure out. I now want to change the form to something like
<form method="POST" action="createpage.php">
<input type="text" name="boxTitle">
<input type="text" name="boxPara">
<input type="text" name="boxTitle">
<input type="text" name="boxPara">
<button type="button"><button>
//the button above will be clicked to bring another set of inputs as seen in the two above using javascript
<button type="submit" name="button">button</button>
</form>
is there any way I can grab the whole form in one array and then split it up every 2 sets of information.
I am hoping the result would come out as something like this
$form = $_POST['(form)']
//$form would then look like this
$form = boxTitle => (aTitle), boxPara => (paragraph), boxTitle => (nextTitle), boxPara (nextParahraph)
it would continue like that for each extra time they clicked the button. Is this possible or am I going to have to rethink my design.
Thanks for any help
Related
I'm currently working on at the displaying of information from a database. I was making a summary site where you can only see the important things of a table. After that i made the first element as an <input type="submit"> in a <form>, so u can click it and come to the detail site. My problem is now: The value of this input type has to be my ID, so i can query correctly on me detail site. I was wondering if it is possible to use something like a placeholder, so that the ID is the value, but on the input type is written other text.
My input:
<form method="post" action="Details.php">
<input type="submit" placeholder = "test" name="Overview" onclick="parent.location='Details.php'" value="<?php echo $data[$i1]; ?>">
</form>
How it currently looks
I want it that the input type still has the same value, but is displaying on the website something else like "test".
Greetings!
No, but buttons can have different values and labels.
<button name="foo" value="bar">baz</button>
Since you are using a form-tag per row, you can add a hidden input-field in the form and set the value of the submit-button to whatever you like.
<form method="post" action="Details.php">
<input type="hidden" name="id" value="<?php echo $data[$i1]; ?>" />
<input type="submit" name="Overview" value="test" />
</form>
Im trying to make a form with Laravel that send two sets of data.
my form is like this.
<form>
<fieldset method="POST" action"some url">
<label for="nameField">Name</label>
<input type="text" id="nameField" name="nameField">
<label for="phoneField">Name</label>
<input type="text" id="phoneField" name="phoneField">
<input class="button-primary" type="submit" value="Send">
</fieldset>
</form>
the first in put nameField will save to the table "names".
the phoneField will save to another table "phones".
Ok! the problem is I want to let user make as many phoneField as they want (with Javascript of course).
so i think the best way is i save nameField like this:
Name::create([ "name" => request("nameField")]);
but how about phoneField? how to save them? users can make about 10 field or more. is there any way to group the phoneFields as any array and send the array with request HTTP?
You can send group of phoneField. Use array for phoneField
<label for="phoneField">Name</label>
<input type="text" id="phoneField" name="phoneField[]">
And in your controller
$data = $request->all();
$phoneFields = $data['phoneField'];
foreach($phoneFields as $phoneField)
{
//implement to save phone number...
}
I am using the value of search form Director1 to auto input in the value of "director_id_1" in the form CompanyDirectors, it is working.
However, if I use search form Director2 to auto input in the value of "director_id_2", it is working but meanwhile the value of "director_id_1" will be empty again.
So, how can I keep the auto input value of "director_id_1" after search Director2 ???
The below code is saved in the same page: Director.php
<h2> Company Director(s) - Input</h2>
<hr style="border: 1px dotted #2c1294;">
<form name="Director1" action="" method="POST" accept-charset="UTF-8" >
<input type="text" name="QueryDirector1" />
<input type="submit" name="DirectorName1" value="Search Name of Director 1 to input ID" />
</form>
<form name="Director2" action="" method="POST" accept-charset="UTF-8" >
<input type="text" name="QueryDirector2" />
<input type="submit" name="DirectorName2" value="Search Name of Director 2 to input ID" />
</form>
<hr style="border: 1px dotted #2c1294;">
<form name="CompanyDirectors" method="post" action="Director_insert.php" accept-charset="UTF-8" >
<b>ID of Director 1:</b>
<input type="number" name="director_id_1" required="required" value="<?php echo $director_id_1; ?>" >
<br>
<b>ID of Director 2:</b>
<input type="number" name="director_id_2" required="required" value="<?php echo $director_id_2; ?>" >
<br>
<input type="submit" name="submit" value="Submit">
</form>
Thank you very much for your help & support first !
If your question (which I find very hard to understand) is:
I want anything already submitted on the first form (Director 1) to be maintained upon submission of the second form (Director 2), and vice versa. How could I achieve this?
Then my answer would be use sessions or the database for persistence.
If I am understanding your question correctly, you do not understand that HTTP requests are (by nature) stateless. In other words: when you submit any form data, it is processed server-side and then ceases to exist. The "state" then disappears.
You could cache the submitted data temporarily in a $_SESSION[...] variable, or you could store it into the database (and retrieve it back out) or use HTML5 storage in the browser or do something less elegant like use hidden HTML inputs in the second form. (Or just use one form.)
Some useful links:
http://www.w3schools.com/php/php_sessions.asp
http://php.net/manual/en/session.examples.basic.php
https://en.wikipedia.org/wiki/Stateless_protocol
So for example:
<?php
session_start();
if (isset($_POST['DirectorName1'])) {
$_SESSION['directors'][1]['name'] = $_POST['DirectorName1'];
}
if (isset($_POST['DirectorName2'])) {
$_SESSION['directors'][2]['name'] = $_POST['DirectorName2'];
}
Then print the values from $_SESSION rather than $director_id_1 etc.
It's hard to help without a full copy of your code.
I have a form located at a url containing get parameters,my form is also using this method.When the form is submitted it rewrites the previos get parameters.
Is there a simple way to rewrite only my form parameters?
I have in mind a Javascript solution ,however I want to know if there is a simpler way?Using HTML/PHP perhaps?
As far as I know, u u are not interested in using JS, then using form's hidden element is only way u have like this-
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
<input type="hidden" name="country" value="Norway">
<input type="submit" value="Submit">
</form>
<p>Notice that the hidden field above is not shown to a user.</p>
The question is how u can use it with PHP, right?
The solution is here-
//In PHP
if( isset($_GET['fromPerson']) )
{
echo $fromPerson;
}
So combined HTML and PHP code will be like this (assuming a get element from prevous page is named fromPerson)-
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
<?php
if( isset($_GET['fromPerson']) )
{
echo '<input type="hidden" name="country" value=".$_POST['fromPerson'].">';
}
?>
<input type="submit" value="Submit">
</form>
Lets say you get a parameter p1 from a get request, it should look like this:
http://server.com/?p1=123
In your form, you can add hidden fields that would have the same effect when you submit, like this:
<form method="GET">
<input type="hidden" value="<?php echo $_GET["p1"]; ?>" name="p1">
</form>
That way you can resend the variables as many times as you need.
I'm not sure I understand your question... Can you post your code?
I assume you mean something like this?
in index.php
<input type="hidden" name="id" value="<?php echo $id; ?>" />
in return.php
Edit
Background: The website I am working on has a search bar at the top. The user inputs a part code for a product and the website returns information about that product.
So, I have a basic search bar that posts parameters from a HTML form into a PHP script, which then does a lookup on a MySQL server to get the Product.
The problem is because some part codes have "#" characters, I have to use Javascript to insert escape characters, otherwise I only get some of the part code in the PHP script.
Example - 123#ABC would be read as 123.
I use a hidden value in the form, which is populated with the Text Box value, modified by the escape() function in Javascript.
This is my code currently, it works in every browser except for IE.
Any help would be much appreciated :)
<script language="jscript">
function changeTextBox()
{
hiddenSearch.value = escape(txtSearch.value);
formSearch.submit;
}
</script>
<form id="formSearch" name="Search" action="?page=search" method="post">
Search by <u>Part Code</u> or <u>Description</u>
<input id="txtSearch" type="text" size="35">
<input id="hiddenSearch" name="Search" type="hidden">
<input name="Submit" onclick='jscript:changeTextBox();' type="submit" value="Submit">
</form>
take a look at changes-- i think there were issues with your javascript.
<script language="jscript">
function changeTextBox()
{
document.getElementById("hiddenSearch").value = escape(document.getElementById("txtSearch").value);
this.submit();
}
</script>
<form id="formSearch" name="Search" action="?page=search" method="post" onsubmit='changeText()'>
Search by <u>Part Code</u> or <u>Description</u>
<input id="txtSearch" type="text" size="35">
<input id="hiddenSearch" name="Search" type="hidden">
<input name="Submit" type="submit" value="Submit">
</form>