How to manipulate form data before sending to server?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
morison20
Forum Newbie
Posts: 2
Joined: Tue Mar 17, 2009 9:40 pm

How to manipulate form data before sending to server?

Post by morison20 »

Hi,
I want to collect 25 schedule times. User will input 25 times using drop down boxes. That means, 25 hour and 25 minutes drop down boxes, making total 50 drop down boxes. But I don't need to send them as individual variables. One string like- 08:05;08:37;09:43;09:59:11:12;12:34 will do.

So, the variable to send will be like- time=08:05;08:37;09:43;09:59:11:12;12:34

I think it will be easy - user presses submit button, all the variables from 50 drop down boxes will make a string and then send that string.

How to do that? any ideas? any suggestion?

Any example or tutorial on this is appriciated.
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: How to manipulate form data before sending to server?

Post by amargharat »

use hour select box name and minute name as follows,

<select name="hour[]">

<select name="minute[]">

and use following php code

Code: Select all

if($_POST["submit"])
{
	$hour = $_POST["hour"];
	$minute = $_POST["minute"];
	
	function emp($var)
	{
		if($var != "")
	    	return $var;
	}
	
	if(count(array_filter($hour, "emp")) != 25 || count(array_filter($minute, "emp")) != 25)
		echo "Please select all the hours and minute";
	else
		{
			$arr = array();
			for($i=0;$i<25;$i++)
			{
				$arr[] = $hour[$i].":".$minute[$i];
			}
			
			echo implode(";", $arr);
		}	
}
Post Reply