Jump to content

Help with dynamically generated buttons in a form


Darkmatter5

Recommended Posts

I have a script that runs inside a form that generates 2 buttons per record. From a query I get a list of users on my site, and create 2 buttons

either

  "activate$member_id" or "deactivate$member_id"

and either

  "suspend$member_id" or "unsuspend$member_id"

 

These buttons are dependent on if the particular member is activated=0 or 1 and if the member is suspended=0 or 1.  So I need a script that can handle all instances of these buttons for each member_id.  So basically.

 

For member 4

if(isset($_POST['activate4'])) { run this code }

if(isset($_POST['deactivate4'])) { run this code }

if(isset($_POST['suspend4'])) { run this code }

if(isset($_POST['unsuspend4'])) { run this code }

 

How should I go about making code that handles these dynamic instances?

Link to comment
Share on other sites

  • 6 months later...

I don' know that this is exactly what you are looking for, but it might work.  . I needed a way to dynamically create web buttons for a web based application I am creating. I created a script that takes a number of parameters to create dynamic consistent looking web buttons on the fly. Pass your text, icon, a set of 3 background images, along with a few other config options, and get buttons like these.

 

http://www.phpwebscripting.com/scripts/button/button.php?bl=bl_green.png&br=br_green.png&bg=bg_green.png&ico=group_key.png&ft=default.ttf&txt=Dynamically%20created&bsln=3&fcr=102&fcg=255&fcb=165&fs=10&ind=2 button.php?bl=bl_blue.png&br=br_blue.png&bg=bg_blue.png&ico=1.png&ft=default.ttf&txt=On%20the%20fly&bsln=3&fcr=165&fcg=165&fcb=255&fs=10&ind=2

 

The buttons shown above were created using the demo of the script. Read the tutorial and try the demo at http://www.phpwebscripting.com/index.php?module=article&view=8

 

I hope this is useful

Link to comment
Share on other sites

I have a script that runs inside a form that generates 2 buttons per record. From a query I get a list of users on my site, and create 2 buttons

either

  "activate$member_id" or "deactivate$member_id"

and either

  "suspend$member_id" or "unsuspend$member_id"

 

These buttons are dependent on if the particular member is activated=0 or 1 and if the member is suspended=0 or 1.  So I need a script that can handle all instances of these buttons for each member_id.  So basically.

 

For member 4

if(isset($_POST['activate4'])) { run this code }

if(isset($_POST['deactivate4'])) { run this code }

if(isset($_POST['suspend4'])) { run this code }

if(isset($_POST['unsuspend4'])) { run this code }

 

How should I go about making code that handles these dynamic instances?

 

i would suggest a different way of structuring your forms. since your user will only be hitting one of these buttons at a time, why not nestle each one of them into their own unique form with a hidden input that designates the member's id and action to be taken? for example:

 

<form action="whatever.php">
<input type="hidden" name="member_id" value="MEMBER_ID_ECHOED_HERE" />
<input type="hidden" name="action_to_take" value="ACTIVATE_OR_DEACTIVATE|SUSPEND_OR_UNSUSPEND" />
<input type="submit" name="submit" value="ACTIVATE_OR_DEACTIVATE|SUSPEND_OR_UNSUSPEND MEMBER MEMBER_ID_ECHOED_HERE" />
</form>

 

this requires really only one processing function, which looks in $_POST['action_to_take'] for the procedure to perform, and $_POST['member_id'] for the id of the member on whom the operation should be performed. it should be noted that the user can change any of these POST values, so it would be wise to make sure you run checks to verify that the operation is possible for the given member (eg. that they aren't trying to unactivate an inactive user).

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.