Jump to content

Recommended Posts

I have a page (below) that has half of a form and I'm using ajax to display the second half of the form (which contains php input) , everything appears fine however, when I submit the form I'm only sending the forms first half!

 

I'm not too familiar with ajax, and when i Google for info about my issue, all I find is info about two stage forms (which this is not).

 

I've also tried moving my submit button around a bit but to no avail. I need to keep the physical layout of my page, however im open to suggestions.

 

For the time being im using action="<?php echo $_SERVER['PHP_SELF']; and a get method, purely so that i can observe which parameters are being passed to the url.

 

my original page:


<?php $user_id = 7; #connection $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "SELECT location FROM snag_score_cards WHERE user_id = $user_id"; $result = mysql_query($sql); $selected_id = isset($_POST['location']) ? intval($_POST['location']) : false; $who = ''; $options = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['location']) { $selected = ' selected="selected"'; } else { $selected = ''; } $options .= "<option value=\"{$row['location']}\"{$selected}>{$row['location']}</option>\n"; } ?>

<div id="formright"> <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label class="dateof" style="margin-left:10px;"> <a href="new_snag_scorecard.php">create new scorecard</a></label><br/><br/> <label class="dateof" style="margin-left:10px; "> Select a Scorecard: </label><br /> <select name="location" style="margin-left:10px; width:200px; " onchange="showUser(this.value)"><br /> <option value="">Select a Scorecard:</option><?php echo $options ?></select><br /><br /> <label class="dateof" style="margin-left:10px;"> Date of Score: </label><br /> <input type="date" name="date" id="date" style="border:1px solid #EBEBEB; padding:0px; margin:0px; height:20px; margin-left:10px; " value=" " /><br />

<?php $result = mysql_query("SELECT * FROM Competitions"); $num_rows = mysql_num_rows($result); if ($num_rows >0) { $selected_id = isset($_POST['Competition']) ? intval($_POST['Competition']) : false; $who = ''; $options2 = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['Competition']) { $selected = ' selected="selected"'; } else { $selected = ''; } $options2 .= "<option value=\"{$row['Competition']}\"{$selected}>{$row['Competition']}</option>\n"; } echo ' <br/><label class="dateof" style="margin-left:10px;" >Select a Competition: </label><br/> <select class="selectstyle" name="competition" > <option class="optionstyle" value="">Select a Competition</option> ' . $options2 . '</select><br/><br/>' ;}

?>

<input type="submit" name="submit" value="submit" id="submit"/> </div><div id="formwrap"> <div id="txtHint"> <!-- ajax loads get_snag_score.php here --> </div> </div> </form>

 

I'm using Ajax to show the below on my page...

 


<?php // Sanitize input function sanitize($in) { return addslashes(htmlspecialchars(strip_tags(trim($in)))); } $q = sanitize($_GET['q']);

echo '<Br/><h2 class="location">' . $q . "</h2>" ; #connection here

$connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "SELECT par1, par2, par3 FROM snag_score_cards WHERE location = '$q'"; $result = mysql_query($sql);

while($row = mysql_fetch_array($result)) { $par1 = sanitize($row['par1']); $par2 = sanitize($row['par2']); $par3 = sanitize($row['par3']); } ?>

<input type="hidden" name="processForm" value="1" /> <input type="text" autocomplete="off" name="Scores" id="Scores" value="Score" class="clip" readonly style="border:0px" > <input type="text" autocomplete="off" name="Par" id="Pars" value="Par" class="clip" readonly style="border:0px" > <input type="text" name="Par Score" id="ParScore" value="Total" class="clip" readonly style="border:0px" ><br>

<input type="text" autocomplete="off" name="sum1" id="hole1A" value="" onchange="calc(this.value,'hole1B','hole1result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par1;?>" id="hole1B" onchange="calc(this.value,'hole1A','hole1result')" > <input type="text" name="sum" value="" id="hole1result" readonly style="readonly"> <br>

<input type="text" autocomplete="off" name="sum1" id="hole2A" value="" onchange="calc(this.value,'hole2B','hole2result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par2;?>" id="hole2B" onchange="calc(this.value,'hole2A','hole2result')" > <input type="text" name="sum2T" value="" id="hole2result" readonly style="readonly"> <br>

<input type="text" autocomplete="off" name="sum1" id="hole3A" value="" onchange="calc(this.value,'hole3B','hole3result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par3;?>" id="hole3B" onchange="calc(this.value,'hole3A','hole3result')" > <input type="text" name="sum3" value="" id="hole3result" > <br>

<input type="hidden" name="location" value="<?php echo $q?>">

Link to comment
https://forums.phpfreaks.com/topic/273326-form-spread-over-2pages/
Share on other sites

You will need to actually submit the first form, and then use sessions (or another temporary storage) to save the results from the first submission while waiting for the second.

Either that, or you have to rewrite your page to make it one form only. Then use JS and CSS to hide or show the relevant parts, using a submit button on the second part only. That way it'll submit everything at once, and still give the impression of it being two forms. Not to mention it'll work for those who don't have JS (activated) as well.

Guest
This topic is now 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.