Jump to content

Handling POST Vars


Drainy

Recommended Posts

Hi,

 

A while ago I posted on here for some help with a calender/booking system I was developing. I have now hit another wall!

So far I have successfully implemented it automatically generating the calender accurately, assigning an ID to each cell which identifies it by the month and day number, eg february3 is the 3rd of feb.

Using javascript and forms I have created a way to save a 1 or a 0 when a cell is selected.

So if a user wanted to book 5 days in feb they can click on the cells for february 5,6,7,8,9 and the javascript assigns a value of 1 to each ID (february5, february6 etc).

All other values which arent selected are automatically assigned a 0.

When I pass this through to the next php script to confirm bookings I hit a wall.

The only way I can see of verifying which variables have had a 1 set is to do an if for every single possible variable, so I would have to type in every single month and day combination.

I am certain there must be an easier way for me to go about this but I can think of one or find one in any functions ive looked at.

Does anyone know of a function or could prod me in the right direction so I can create a solution to this?

Link to comment
Share on other sites

It depends on how you have your form setup.  In order for values to be passed to the server, you have to name the element with the name attribute.  The server doesn't care about the id attribute; that's a clientside thing.  If your cells are not form elements, you will need to use javascript to grab the id of the flagged cells and put it in a variable (array would be better, since you're wanting to have multiple values) that can be posted.  You'd have to use for instance onsubmit and call a function or something.  I can't really be more specific than that without seeing actual code.

Link to comment
Share on other sites

<input type='hidden' name='$titlelower$daynum' id='$titlelower$daynum' value='0'><td align=center bgcolor=#000000 onClick=\"booking('$titlelower$daynum');tabClick(event)\">$daynum</td>

Each TD is defined as above. the onclick booking is what assigns a value of 1 or 0, dependant on if 1 or 0 is already set (it toggles between them).

The tabclick event is simply to change the cell colour so the user can identify visually what they have selected.

As this is inside of a PHP script the name of each form element is based on the month and day number.

I just then submit this to another script, at the moment all this does is display the entire contents of the POST vars just so I could verify that it is correctly selecting and de-selecting data and then passing it over.

So at the moment if I was to select the 1st, 3rd, 4th and 7th and then submit my verification page displays the following;

Array ( [february1] => 1 [february2] => 0 [february3] => 1 [february4] => 1 [february5] => 0 [february6] => 0 [february7] => 1 [february8] => 0 [february9] => 0 [february10] => 0 [february11] => 0 [february12] => 0 [february13] => 0 [february14] => 0 [february15] => 0 [february16] => 0 [february17] => 0 [february18] => 0 [february19] => 0 [february20] => 0 [february21] => 0 [february22] => 0 [february23] => 0 [february24] => 0 [february25] => 0 [february26] => 0 [february27] => 0 [february28] => 0 [submit] => submit ) 

Does that help clarify what im doing?

Link to comment
Share on other sites

Thanks for that, its given me some ideas and its made me shoot off and try and create a function for that. Its crashing and burning at the moment though, JavaScript isnt a strong point of mine so ive had to try and craft it from what I am reading at the moment.

Can you help with javascript or am I best off posting in the JavaScript forum?

 

Just for refence if you can help;

function booking(id) {  

var currentDay = document.getElementById(id);

	if (document.getElementById(id).value == null) 
	{  
		var newNode = "<input type='hidden' name='" + id + "' id='" + id + "' value='1'>";
		var parent = document.getElementById("content");
		parent.insertBefore(newNode,document.getElementById(id));
	}
	else
	{
			  currentDay.parentNode.removeChild(currentDay);
	}
}

That is what I believe should create or destroy but its not working at all at the moment, I am having a hard time getting my head around what some parts of this are doing.

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.