Jump to content

Handling Several Form Inputs


fesan

Recommended Posts

Hi...

 

I have a web page that writes out several rows from a database. The rows are printed directly into forms so it is easy to update.

One of the fields is a date field where the user could enter the date with a Java-script date-picker. To not change all the date input fields at once every input needs a separate name even so that there is only one form submitted at a time. To create separate names for each input filed created by PHP i could just use a while loop for number of output rows left. But when the form is submitted and i need to handle the single input from one form but i don't know which... hos can i solve this?

 

The Form:

echo '<form id="form1" name="form1" action="edit.php?task=edit&id='.$row['id'].'" method="POST">';
echo '<td><input readonly="readonly" type="text" name="dato" id="dato" class="'.$class.'" value="'.date('d.m.Y', strtotime($row['dato'])).'" /></td>'; // date1, date2. etc.

 

The process script:

$dato = !empty($_POST ['dato']) ? $_POST['dato'] : ''; // i need to set this variable to the correct one.
if($_GET['task'] == 'edit') {
include("admin/conn.php");

$sql = "UPDATE ${dbtable} SET
dato = '$mysql_dato',
kunde = '$kunde',
kontaktperson = '$kontaktperson',
telefon = '$telefon',
epost = '$epost',
type = '$type',
status = '$status',
lyd = '$lyd',
lys = '$lys',
kommentar = '$kommentar',
last_edit_by = '$last_edit_by',
email_sent ='ikkesent'
WHERE id = '$_GET[id]'";

$result = mysql_query($sql, $conn) or die (mysql_error());
$_SESSION["message"] = "Eventinfoen er endret.";
header("Location: http://bahrawy.net/dlight/ballroom/index.php");
}

 

The Javascript that connects the input to the java:

<script type="text/javascript">
$(function() {
$('#dato').datepick({dateFormat: 'dd.mm.yyyy'});
});

</script>

 

Did i in some way explain my issue so it is understandable?

Link to comment
https://forums.phpfreaks.com/topic/269787-handling-several-form-inputs/
Share on other sites

Not too sure If I got you right.

 

If it is a single form with multiple rows of input and other fields you could name your fields as so

<input name="row1[mydate]">
<input name="row1[myname]">
<input name="row2[mydate]">
<input name="row2[myname]">

 

If you have multiple forms, then just give the forms itself different names and set hidden fields for the row ids

No, that was not it, but you got me thinking. :)

Thanks for that! I solved this by adding the row id to the fields name and retrieving it on the post page.

 

Form:

echo '<td><input readonly="readonly" type="text" name="dato'.$row['id'].'" id="dato'.$row['id'].'" class="'.$class.'" value="'.date('d.m.Y', strtotime($row['dato'])).'" /></td>';

 

Handler / Post page:

$date_make = "dato" . $_GET['id'];
if(!empty($_POST[$date_make])){$dato = $_POST[$date_make];} else {$create = 1;}

 

Thanks for the thinking help!! :)

Only thing left is to make all the java variables with php... :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.