Jump to content

Looking for a clean approach to my solution


jessadactyl

Recommended Posts

Hey guys! I'm building a web application that requires a template system and I'm looking for a clean way to achieve this solution:

 

When the "Template Manager" page is loaded, users will be prompted to either load an existing template or create a new one. Upon form submission their choice will be interpreted and appropriate functions will be executed.

 

The problem is I figured I would use a URL parameter (template.php?t=139) to determine which existing template within the MySQL database should load. If no parameter is found, the load/create form will be displayed instead of the template editor.

 

This approach works fine for simply loading an existing template since a select menu "onchange" event simply reloads the page adding the ?t={id} prefix. The creation of a new template however requires the use of form action="template.php".

 

Obviously the template ID is unknown until the page reloads, validation is handled and my createTemplate($txt_tplName); method is executed. At this point however there is no clean solution to have the page reload with the template.php?t={new id returned from create template function}

 

Any cleaner solutions would really be appreciated! (I'd prefer not using AJAX, simply to keep a feeling of consistency.)

Link to comment
Share on other sites

Unless i've misunderstood, it sounds to me like you just need to re-organise your script a touch.

 

The creating of a new id for a new template should occur before you check the URL for a given ID. You should then only check the URL if a new id has not been created. If it hasn't use the ID in the URL. If it has, use the created ID instead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.