PDA

View Full Version : PHP help ! Submit the form



binladun
June 23rd, 2003, 01:58
Hi !

This is my HTML code - file name "form.html"


<html><body>
<FORM method=POST action=script.php>
<input type=hidden name="abc" value="value_abc">
<input type=hidden name="def" value="value_def">
<input type=hidden name="xyz" value="value_xyz">
<input type=submit value=Submit>
</FORM>
</html></body>

I've wrote the "script.php" which can print to browser like this

abc|value_abc
def|value_def
xyz|value_xyz

This is what I have done - "script.php"


<?php
print "abc|$abc<br>def|$def<br>xyz|$xyz";
?>

And now - I need your help to write an advance "script.php"

I want that if I go to modify "form.html" -
change the field name "abc" to "new_abc" and new value for that field (see below)

<input type=hidden name="new_abc" value="new_value_abc">
<input type=hidden name="new_def" value="new_value_def">
<input type=hidden name="new_xyz" value="new_value_xyz">

Then when I submit the form - it will print out correctly like this



new_abc|new_value_abc
new_def|new_value_def
new_xyz|new_value_xyz

Hope you understand what I mean -

The "script.php" will print out correctly field_name|field_value even if I add or remove the form field.

Thanks

Loon
June 23rd, 2003, 04:17
Hmm, it's a little early to be thinking hard :classic2: but i guess you could include some sort of config file into the form and script.php like

;config file

$name1 == "new_abc";
$value1 == "new_value_abc";
$name2 == "new_def";
$value2 == "new_value_abc";
$name3 == "new_xyz";
$value3 == "new_value_abc";

;form

<input type=hidden name="<? echo $name1; ?>" value="<? echo $value1; ?>">
<input type=hidden name="<? echo $name2; ?>" value="<? echo $value2; ?>">
<input type=hidden name="<? echo $name3; ?>" value="<? echo $value3; ?>">

then you should be able to

$_POST['$name1']
$_POST['$name2']
$_POST['$name3']

etc, in your script.php then when you change the info in the config file it should always get the new names

I'm sure that's not perfect but mabye you can get something working from that, though there's probally an easier way with fixed "names" and using an array to get name1, name2 etc

dawizman
June 23rd, 2003, 10:26
Or you could place the values into a database.