0

I'm kinda rookie at PHP but i'm trying to developing a backoffice with some tables and value-editing options.

By now, i have tables like this:

enter image description here

But i'm kinda bugged with this issue:

The change button is being implemented like this:

for ($i = 0; $i < count($a); $i++) {
            ?>
            <tr>
            <td><i onclick="
            document.form1.deviceFeatValID.value = <?php echo $a[$i][DEVICE_FEATURE_VALUE_ID] ?>;
            document.form1.deviceID.value = <?php echo $a[$i][DEVICE_ID] ?>;
            document.form1.deviceClassFeatID.value = <?php echo $a[$i][DEVICE_CLASS_FEATURE_ID] ?>;
            document.form1.deviceFeatureVal.value = <?php echo $a[$i][DEVICE_FEATURE_VALUE] ?>;
            document.form1.submit();" class="icon-refresh" ></td>
            <td><?php echo $a[$i]['DEVICE_FEATURE_VALUE_ID']; ?><td><?php echo $a[$i]['DEVICE_ID']; ?><td><?php echo $a[$i]['DEVICE_CLASS_FEATURE_ID']; ?><td><?php echo $a[$i]['DEVICE_FEATURE_VALUE']; ?>
            </tr>
            <?php
            }
            ?>

That is, by Javascript, i set the input values of this form, in the same .php:

<form name="form1" method="post" action="deviceFeatureValueFRM.php">
            <input type="hidden" name="deviceFeatValID"/>
            <input type="hidden" name="deviceID"/>
            <input type="hidden" name="deviceClassFeatID"/>
            <input type="hidden" name="deviceFeatureVal"/>
            <input type="hidden" name="hiddenTypeField"/>
        </form>

But...do you consider that this is a good practice? Is there another solution?!

The goal of this code is to detect which line is going about to be edited.

Kind regards,

Sam

2
  • 1
    Yes. Why not define them in PHP? Also, you're using obtrusive JS which is bad practice, too... Commented Mar 7, 2013 at 13:07
  • I already tryed: I left that form intact, and instead the refresh icon, i used the submit input button. But how can i set each form hidden inputs by php? Thank you for your fast response BenM :) Commented Mar 7, 2013 at 13:11

2 Answers 2

2

Why do this with javascript? Just give the input field a value as such:

<input type="hidden" name="deviceFeatValID" value="<?php echo $a; ?>"/>

Where $a can be any variable you would like.

Sign up to request clarification or add additional context in comments.

4 Comments

But the form aims to another page and i want to know which input submit button was pressed :). Thank you for your fast response SeanWM :)
You can easily detect which submit element was clicked by assigning them with different names (or values)...
Ok, that's possible if you have a fixed number of buttons. But in my case i don't know, at first glance how many rows i'm gonna have :S Thank you for your fast response :)
And you say assign different names how? By concatenating strings?
0

Well, I would recommend that you had all files separately. So let's say you had one file for PHP. One file for Javascript, and one for HTML. So if you want to use php functions or whatever just need to call them via AJAX.

That way you will have a cleaner code and a bit more secure one.

1 Comment

Thank you for your fast response. I already set up multiple files once, and i know that the example i put in the question isn't perfect :). But i have priority in trying to avoid javascript in the passage of parameters on the form, by clicking the change button and knowing precisely which button was pressed :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.