Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Logic letting me down!

  • 31-03-2011 12:32pm
    #1
    Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭


    I have been teaching myself a language over the last few months and while I find the actual language fine (e.g understanding certain principles like loops, arrays, indexes, variables etc) I find that I am not in the correct mindset for certain programming logic. An example is as follows:

    I have written a web form that populates the input boxes on the page with values from a file. The idea is that a user would be able to change these values then submit the form for change. My problem is: is it considered the norm to send the whole page (every input box) to the edit script and rewrite the file? This way I find the easiest, I submit the whole page to an edit page and then just opens the file and writes every value passed to it from the form even if that field hasn't changed.
    I am wondering if it is better practice to have each field its own form and submit that to its own edit page. The down side to this is that I would need an edit script for each value!

    Any suggestions?


Comments

  • Registered Users, Registered Users 2 Posts: 7,041 ✭✭✭Seachmall


    That sounds about right, depending on how you're going about it of course. On the backend are you going through the POST/GET params piece by piece or do you have a loop doing it? If it's not looping you should probably do it that way, if you're doing it piece by piece then that's a lot of code to maintain (depending on the size of the form).


    If you're using GET and you really don't want to send redundant fields you could add a "onchange" attribute that adds the fields to an array, then when it is submitted have JS function to urlencode only those fields. Then redirects the user to the page with the params appended to it and returns false (so the form doesn't actually submit).

    If you're using POST you could do the same thing but instead of having JS redirect just disable all the fields that haven't been changed (or are empty) and return true (so the form will submit).

    It's not the most elegant of ways though.


  • Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭azzeretti


    Seachmall wrote: »
    That sounds about right, depending on how you're going about it of course. On the backend are you going through the POST/GET params piece by piece or do you have a loop doing it? If it's not looping you should probably do it that way, if you're doing it piece by piece then that's a lot of code to maintain (depending on the size of the form).


    If you're using GET and you really don't want to send redundant fields you could add a "onchange" attribute that adds the fields to an array, then when it is submitted have JS function to urlencode only those fields. Then redirects the user to the page with the params appended to it and returns false (so the form doesn't actually submit).

    If you're using POST you could do the same thing but instead of having JS redirect just disable all the fields that haven't been changed (or are empty) and return true (so the form will submit).

    It's not the most elegant of ways though.

    Thanks for the reply.
    I wasn't using a loop, but now you suggest it it makes a lot more sense than trying to maintain all those field variables.
    It's a CGI script by the way, I didn't think the language would matter so I didn't mention it!


Advertisement