Jump to content

Self submitting a form - pass it to a session ... any idea's


Accurax

Recommended Posts

Hi chaps...

 

Ok i have the following form... which self submits when a user selects one of the many radio buttons.

 

<?php
if(isset($_POST['myform'])){
echo "form submitted";
}
echo "<form method='post' action='" . $self . "'>";
echo "<input type=radio name='myform' value='" . $row['title'] . "' onchange='this.form.submit();'>";
echo "</form>";
?>

 

I need to get this submitted form value into a session somehow.... but at the moment i cant seem to make the page accept the form was submitted.

 

I was hoping someone may be able to point me in the right direction to gettng this working? ... i think it may have something to do with the way the page is processed ie.. php on the server JS on the client.... its a strange old problem ... any and all advice seriously appreciate d!!

 

Accy

 

Hmmm ... that doesnt seem to help my friend.... :(

 

<?php
if(isset($_POST['myform'])){
echo "form submitted";
}
echo "<form method='post'>";
echo "<input type=radio name='myform' value='" . $row['title'] . "' onchange='this.form.submit();'>";
echo "</form>";
?>

If $self isn't being set then it would already be doing that.

 

I'm wondering if the form is actually submitting at all, you might want to try changing the 'onchange' to 'onClick'.

 

Doesnt seem to make any difference.... the form looks like its submitting... the page refreshes, but my conditional never seems to hold true :( ....

Here's some code that works correctly... tyhere are clear differences, but maybe someone will spot something i've missed

 

<?php
if(isset($_POST['myform'])){
echo "waaaahey";
}
?>
<form method="post">
<input type=radio name='myform' value='test' onchange='this.form.submit()'>
</form>

 

As you can see when the form and onChange even are outside of the php then it works correctly..... problem is i need to produce my radio buttons via a while loop, so that isnt an option :(

Was '$row['title']' being set before? It might not have been setting correctly, or believing it was set correctly as it didn't have a value.

 

That's the only difference I can see which could have caused a problem. Although saying that, I ran your original code on my localhost and it worked fine.

$row['title'] gets set just before the form starts

 

heres the complete code... including the loop im using:

 

<?php
		$id = $_SESSION['customer_id'];
					$query = "SELECT * FROM mytable WHERE customers_id='$id'";
					$result = mysql_query($query)
							or die ("could not find name");
		echo "<table id=\"pres_box\" cellpadding=\"0\" cellmargin=\"0\">";
		echo "<form method='post' action='" . $self . "'>";
		echo "<tr>";
		echo "<td colspan=\"2\" class=\"title\">";
		echo "Select your option";
		echo "</td>";
		echo "</tr>";
while ($row=mysql_fetch_array($result)) {
		echo "<tr>";
		echo "<td>";
		echo $row['title'];
		echo "</td>";
		echo "<td>";
		echo "<input type=radio name='myform' value='" . $row['title'] . "' onChange='this.form.submit();'>";
		echo "</td>";
		echo "</tr>";
}
		echo "</form>";
		echo "</table>";

?>

 

how would i go about ending and restarting the while loop... as you can see i need a radio button for each entry in the database... this could be anything from 1 - 100

Ah ok :).

 

while ($row=mysql_fetch_array($result)) {
?>
         <tr>
         <td>
         <?php
          echo $row['title'];
          ?>
         </td>
         <td>
         <input type='radio' name='myform' value='<?php echo $row['title'] ?>' onChange='this.form.submit();'>
         </td>
         </tr>
<?php
}

this shouldnt be this difficult surley .... its still doesnt work.... heres the conditional imusing to check if the form is submitted:

 

<?php
if(isset($_POST['prescription'])){
echo "waaaahey";
}
?>

 

ive tried this before and after the while loop and to no avail... i just dont know whats wrong :(

 

sorry to keep pestering but i really am stumped

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.