Jump to content

Form+List / Help


godsent

Recommended Posts

I'm trying to make code that redirects to selected page from form list.

This code not working correctly because gets "cat" before its even selected so its basically 1.

 

<form action="?id=<?php print $_POST['cat']; ?>" method="post">
<select name="cat">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
<option value="5">five</option>
</select> 
<input type="submit" name="Submit" value="Accept" />
</form>

 

i don't really know how this form should be made. If you know please help

Link to comment
https://forums.phpfreaks.com/topic/137196-formlist-help/
Share on other sites

Keep your form as the following;

 

<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post"> 
<select name="cat">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
<option value="5">five</option>
</select>
<input type="submit" name="Submit" value="Accept" />
</form>

 

#$_SERVER['PHP_SELF'] used to send the request to the current page

 

and on the receiving page (using the script above it'd be the same page) something like the following

 

<?php
$cat = (is_numeric($_POST['cat']))? $_POST['cat'] : 0;
$id = $cat;
?>

Link to comment
https://forums.phpfreaks.com/topic/137196-formlist-help/#findComment-716684
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.