Jump to content

Recommended Posts

Hi all, I'm trying to create my own calendar where data can be entered by an admin through a form.  The calendar and the form are both created dynamically and each day is identified by the date.  I was wondering if there was a way to pass a variable to $_GET[] that would correspond with the day that the admin wishes to enter an event for.  I tried $_GET[$day_id], but that doesn't work.  It doesn't seem to accept variables in the brackets.  I know that if I can get it to accept the variable it should work because if I force the date by doing something like $_GET['6302009'] it works, but I can't do that for each and every day.  Is this possible? 

Link to comment
https://forums.phpfreaks.com/topic/164276-using-variables-with-_get/
Share on other sites

I tried $_GET[$day_id], but that doesn't work.

Seems the link you're using is not quite right. You should setup you links like so

<a href="filename.php?date=YOUR_DATE_ID_HERE

 

Now in your code you'd use the variabled called $_GET['date'] to retrive the requested date id.

Thanks wildteen88.  That works great.  Now the next step I need is to get the data from the text box corresponding with that date.  Currently I have each text field set up with a name corresponding to the date on the calendar.  So if you want to add an item to 6/30/2009, the text field  is named "6302009_form_text" and I need to get the text from that text field.  I can't seem to figure out a way for it to work the same as getting the date.  If I use a hidden field like I did for the date, I don't know how I can populate it with the data from the text field.

Ok, I'm going to try restating what I need at this point.  I have a "date" variable that needs to be combined with a string and then passed into $_GET[].  I need something like $_GET[$date . '_text'].  Is it possible to pass a variable into $_GET sort of like this?  Since the name of the field changes with each date on the calendar, I haven't found a way to give it a normal value like $_GET['date_text'].  Also, I should probably mention that this variable is coming from a text field (which is named via a variable) in my form which contains the data that I am trying to retrieve.  $_GET['6302009_text'] should give me the text that was entered into the text box for the date 6/30/2009, but I can't specify each date like that since I want it to span any number of years.

Well, the whole calendar is created with loops and variables basically, so I don't have the code for each day explicitly written out.  Also, each day has a form associated with it so that data can easily be added for that day. Say you want to put "Go to grocery store today" on January 1st, then you go to January 1st and  under that day is the form with a text box.  You enter "Go to grocery store today" and click "Save".  Here's the code that's generated for each day... this one piece of code is in a loop so that it's automatically generated for each day...

<form name='$form_name_var' action='edit.php' method='get'>
   <input type='text' name='$form_text_var' />
   <input type='submit' value='Save' name='$form_button_var1' />
   <input type='hidden' value='$date_edit_id' name='current_id' />
</form>

 

So when some text is entered into the text field ("$form_text_var", which ends up getting a value like "1012010_form_text" when the day is created) and the "Save" button is clicked, then how do I get that text from the text field because apparently $_GET['$form_text_var'] doesn't work.

Yes, but I thought it would be a good project to practice with and something I could use still.  Now I've built this whole system and almost got the whole thing working like I want it.  When I've searched around for this problem I'm having, I can't seem to find a solution.

Maybe posting all of the code would make a bit more sense... If you have a text field in your form named 712009_text, and the form method is set to GET, on the next page the data in that field is available via $_GET['712009_text'].

 

a good way to demonstrate that would be to create your form, submit it to the action page, then on that action page do

print_r($_GET)

which will recurively print the $_GET array's contents.

 

Or, maybe I am completely misunderstanding what you are trying to do which leads back to post all of the code :)

First of all, I would like to specify that my question really just comes down to, is it possible to do something like $_GET['$someVar']?  If not, I'll have to figure something else out anyway.

 

Now, Matthew...

 

Yes, if I had specified each day of the month in the form with

 

<form name='myform1' action='edit.php' method='get'>
   <input type='text' name='1012009_form_text' />
   <input type='submit' value='Save' name='1012009_text' />
   <input type='hidden' value='1012009' name='current_id' />
</form>

<form name='myform2' action='edit.php' method='get'>
   <input type='text' name='1022009_form_text' />
   <input type='submit' value='Save' name='1022009_text' />
   <input type='hidden' value='1022009' name='current_id' />
</form>

...

<form name='myform31' action='edit.php' method='get'>
   <input type='text' name='1312009_form_text' />
   <input type='submit' value='Save' name='1312009_text' />
   <input type='hidden' value='1312009' name='current_id' />
</form>

 

then I could just use $_GET['1012009_form_text'], $_GET['1022009_form_text'], ..., $_GET['1312009_form_text'], etc.  But that just covers 1 month (and I'm thinking would take just as many "if" conditions as well).  I would also then have to do that for each actual day.  If this were working today and someone wanted to enter something in say, December 2010, I'd have to essentially specify the table, cells, and form, for something like 500 days.  To get around having to doing that I have a loop creating those days and inserting the variables for the days into a form that looks like this...

 

<form name='$form_name_var' action='edit.php' method='get'>
   <input type='text' name='$form_text_var' />
   <input type='submit' value='Save' name='$form_button_var1' />
   <input type='hidden' value='$date_edit_id' name='current_id' />
</form>

 

So I tried $_GET['$form_text_var'], but that doesn't work.  I did print_r($_GET) and I entered text into the 6/2/2009 form which gave me " [6022009_form_text] => 111", but I still have the same problem, because I should have just as easily entered data into 6/2/2050 and it would have given me "[6022050_form_text]".  So the passing of variables for that is working fine, but I couldn't set it up to foresee that and do a condition that would explicitely write out $_GET['6022009_form_text'].

 

I hope that helps and doesn't just make it more confusing lol.

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.