0
echo "<input value='$variable' type='submit' id=submit' name='submit'>";

That variable is an array which keeps repeating and changing numbers. (e.g. 1-20).

Now using a switch statement to access the input submit button when pressed:

switch($_POST[submit]) {
case '':
break;
}

I cant figure out what code to construct and use to check if one of the numbers has been selected (apart from the obvious 1-20 which is not an option).

Any Ideas?

Thanks, Regards X

4
Contributors
12
Replies
13
Views
9 Years
Discussion Span
Last Post by OmniX
Featured Replies
  • I don't think you can use is_int() since all HTTP data is considered strings. There is no type distinction in HTML FORMS or HTTP GET/POST responses. You could check for range: [CODE] if ($var > 0 && $var < 100) { }[/CODE] Or you can use something like: [CODE]if (intval($var) … Read More

0

I cant figure out what code to construct and use to check if one of the numbers has been selected (apart from the obvious 1-20 which is not an option).

What exactly do you mean by that ? Do you want to access the value of $variable when submit button is clicked ? If thats the case, then the simplest method would be to assign the value of $variable to a hidden form variable(using the onclick event).

0

Hmmm ok.

For example say the variable is:

//Note: I have alot of input buttons with SAME NAME/ID but DIFFERENT VALUES (but there all integer)

$submitNumber= 100 // Then changes to 78, Then changes to 64, etc

<input type="submit" value="$submitNumber" name="submit" id="submit">

switch($_POST[submit]) {
case "$submitNumber":
break;
}

Then whenever any of the values from $submitNumber is clicked it selects that switch statement's case. I was thinking maybe making all the $submitNumber integers and then searching the switch statement and have a case that if any number are selected do this?

I know its confusing but I hope that helps =(

Thanks for your help, Regards X

0

You can access the value of the submit button using $_POST. You can then use it in a switch statement or a if loop. :confused:

How can you have input buttons with same name ? For example, If there are 2 buttons with the same name, how can you validate if that particular button was clicked ?

0

You can do that because they both call the switch statement and then depending on the value of the input statement, X occurs.

Im trying to find some sort of case to put in the switch statement that detects "any integer value". Any ideas?

0

Calling switch statement is fine. But Say for example you have 2 textboxes with the same name. While requesting the values, dont you think the value of 1 textbox will be overwritten by the other ? But anyway, coming back to your question. If you want a function to detect any integer value, you can make use of is_int.

0

ya wouldnt work with textfields just buttons unless u were referencing the value of the text field. Anyways ya i tried is_int wasnt working.

I was using is_int like this:

is_int($variable)? "YES":"NO";

This wasnot working as a case then i tried to make it a seperate variable and the use the case to call YES but that didnt work either =(

Maybe an example of is_int you could demonstrate then I can try fiddle around and implement it in my webpage? Thanks

0

ive worked something out uisng is_int() but as i had the case as default and the a header the page is coming up as white. ZZZZzzzz maybe once i get back from work I can try work something out. =(

1

I don't think you can use is_int() since all HTTP data is considered strings. There is no type distinction in HTML FORMS or HTTP GET/POST responses.

You could check for range:

if ($var > 0 && $var < 100) {

}

Or you can use something like:

if (intval($var) > 0) {}

this would make strings equal to 0. So would work unless you also wanted to test specifically for 0.

if (intval($var) > 0 || $var === '0') {}

if anything, you could revert to using regex. But for simple tests I wouldn't invoke Regex as its a pretty heavy application for such a simple task.

I'm sure there is a simple solution to your problem.

Comments
Thanks for the helpful advice =)
0

I came up with a solution using an if statement and session. Thanks for all the help though people =)

0

Instead if the "if statement and session" which is not elegant php coding you might try this:

<input type="submit" name="do" value="Insert Record"  />
<input type="submit" name="do" value="Delete Record" />


<?php
switch ($_POST)
{
case 'Insert Record': echo "insert record";
case  'Delete Record': echo "record deleted";
}
?>

Edited by happygeek: fixed formatting

0

forgot the break command

i.e.


<?php
switch ($_POST)
{
case 'Insert Record': echo "insert record";break;
case 'Delete Record': echo "record deleted";break;
}
?>

0

Ya thanks for the input but thats what i was using already i need something else hence I used an if statement with a session statement also. =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.