Jump to content

Recommended Posts

When this form is submitted, it is automatically resubmitted using JS.

 

All my fields are carried over in the $_post except for total, and state which are radio buttons and a drop down.

 

<p><input type="radio" name="Total" value="30" /> 1 Ticket - $30</p>
<p><input type="radio" name="Total" value="50" /> 2 Tickets - $50</p></td>
  </tr>
  <tr><td><p><strong>First Name:</strong></p>
<p><INPUT TYPE="text" NAME="FirstName" VALUE="<?=$_POST['FirstName']?>"></p></td>
<td><p><strong>Last Name:</strong></p>
<p><INPUT TYPE="text" NAME="LastName" VALUE="<?=$_POST['LastName']?>"></p></td></tr>

 

Obviously I can't change the value of Total to $_POST['Total'] since that hasn't been set yet. What can I do here?

There is no instance of a "state" value in the sample code, so I won't comment about that.

 

I put the following into a HTML file:

<html>
<form action="phpFreaksTest.php" method="POST">
  <input type="radio" name="Total" value="30" /> 1 Ticket - $30<br/>
  <input type="radio" name="Total" value="50" /> 2 Tickets - $50<br/>
  <input type="submit" value="Submit"/>
</form>
</html>

and then print_r($_POST) in the handling page and the total value passes over fine as expected. $_POST['Total'] becomes either 30 or 50 depending on user selection. If you are losing the value of $_POST['Total'] in your script, I am guessing it is being lost somewhere between user clicking submit and javascript submitting data to the server for PHP to handle.

I guess I wasn't exactly clear.

 

What I mean is this:

 

1. User fills out the form, selects 1 ticket and clicks submit

2. The page is redisplayed with all the user submitted text fields filled out.. ie first and last name. However the Tickets radio button is now no longer selected

3. The form is then sent to a 3rd party page where again the text fields are filled out with the user data, however the radio buttons and the drop down are not-- because unlike first and last name the value doesn't equal $_POST['whatever']

 

Does this make more sense?

<input type="radio" name="Total" value="30" <?php if ($_POST['Total'] == '30') { echo 'checked'; } ?>/> 1 Ticket - $30<br/>
<input type="radio" name="Total" value="50" <?php if ($_POST['Total'] == '50') { echo 'checked'; } ?>/> 2 Tickets - $50<br/>

That didn't work.

 

I was trying this but the post value is empty

 

<?php if(!$_POST){ ?>
<input type="radio" name="Total" value="30" /> 1 Ticket - $30</p>
<p><input type="radio" name="Total" value="50" /> 2 Tickets - $50</p></td>
<?php } else { echo "<input type=\"text\" name=\"Total\" value=\"". $_POST['Total'] . "\" >"; } ?>

this code?

<?php if(!$_POST){ ?>
<input type="radio" name="Total" value="30" /> 1 Ticket - $30</p>
<p><input type="radio" name="Total" value="50" /> 2 Tickets - $50</p></td>
<?php } else { echo "<input type=\"text\" name=\"Total\" value=\"". $_POST['Total'] . "\" >"; } ?>

 

yes.

<?php if(!$_POST){ ?> is saying "if the $_POST variable doesn't exist". You are actually interested in $_POST['Total'] and when you are submitting the form, some $_POST fields are coming over. therefore, the if statement will NEVER be true and executed unless no post data is submitted. it is only useful for an initial page load, but what about this circumstance:

 

user loads initial page (radios are output)

user selects form data but forgets to click a radio

else { } is executed - there is no $_POST['Total'] data (even if you weren't losing the data like you are now) so your form is now rooted.

 

you should change it to: if (!isset($_POST['Total'])) { output default radios }

however, you can also use the code I pasted, which simply checks for a value of $_POST['Total'] and echos "checked" if it is either 30 or 50.

 

data loss is not really going to show up in the code you have pasted because you said you are using JS to submit the form. My guess is you are losing the data in the JS.

also, just because one or two or x amount of OTHER fields are coming over fine doesn't mean anything. it might be one little typo preventing the $_POST['Total'] value coming over.

I don't believe the JS is doing anything at this point. This is just the user clicking submit

 

 

This is the code above the form

 

if(!$_POST['db']) { $action = 1;
?>
<form name='form' method='POST' action='test3.php'>
<?
}
else { $action = 2 ;
include('includes/config.php');

?>
<FORM name='form' ACTION="removed" METHOD=POST>
<? } ?>
<table class="form1" width="100%" border="0">
  <tr>
    <td colspan="3"><p><strong>Please enter your information. Name and address must match credit card billing address. All fields are required</strong></p>
<p>How many tickets would you like to purchase? Bring a friend and save $10</p>   
<p><input type="radio" name="Total" value="30" /> 1 Ticket - $30</p>

 

var_dump:

array(24) { ["Total"]=>  string(0) "" ["FirstName"]=>  string(7) "edited" ["LastName"]=>  string(6) "edited"

 

 

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.