dimanche 29 mars 2015

Sending information from one form to another form PHP

I am trying to allow a user to add a 'proposal' and then add tags to it by clicking on another modal. I am unsure of how to handle the process of a user selecting 3 tags and then appending them as hidden values in the initial form. This is the php page where the forms are located:



<div id="addPModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="addPModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">View Proposal: </h4>
</div>
<div class="modal-body">
<form id="addForm1" action= "process.php" method="post">
<div class="form-group">
<label for="code" class="control-label">Proposal ID:</label>
<input type="text" class="form-control" id="proposal_id" name="proposal_id" readonly value ="NULL">
</div>
<div class="form-group">
<label for="title" class="control-label">Enter Proposal Title:</label>
<textarea type="text" class="form-control input-xlarge" rows="2" id="proposal_title_id" name="proposal_title"></textarea>
</div>
<div class="form-group">
<label for="title" class="control-label">Enter Proposal Description:</label>
<textarea type="text" class="form-control input-xlarge" rows="10" id="desc_id" name="description"></textarea>
</div>
<?php

include "db_conx.php";

try {

$db_conx = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);

$db_conx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt3 = $db_conx->prepare('SELECT * FROM course_details ORDER BY course_title');
$stmt3->execute();
$courses = $stmt3->fetchAll(PDO::FETCH_ASSOC);
}

catch(Exception $e)
{
die ("Could not connect to the database $mysql_dbname :" . $e->getMessage());
}
?>

<button type="button" class="btn btn-primary pull-right" data-toggle="modal" data-target="#addTModal" data-id="#">Select Tags <span class="glyphicon glyphicon-tags"/></button>

<div class="control-group">
<label class="control-label" for="course_details">Select Course:</label><p></p>
<select name="course">
<option value=''>Select One</option>";
<?php foreach($courses as $course): ?>
<option value="<?php echo $course['course_code'] ?>"><?php echo $course['course_title'] ?></option>
<?php endforeach ?>
</select>
</div> </p>



<div class="modal-footer">

<div class="btn-toolbar">
<button type="button" class="btn btn-default" class="pull-right" data-dismiss="modal">Close</button>
<input type="hidden" name="user_token" value="<?php echo $_SESSION['user_token']; ?>"/>
<button type="button" class="btn btn-success" class="pull-right">Submit <span class="glyphicon glyphicon-saved"></button>

</div>
</div>
</form>
</div>
</div>
</div>
</div>

<?php

include "db_conx.php";

try
{

$db_conx = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);

$db_conx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db_conx->prepare('SELECT * FROM tag_details ORDER BY tag_title ASC');
$stmt->execute();
//$count = $stmt>rowCount();
$tags = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch(Exception $e)
{
/*** if we are here, something has gone wrong with the database ***/
$e->getMessage();
}


?>

<div id="addTModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="addTModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Showing All Tags </h4>
<p class="text-danger"><small>(Select up to 3)</small></p>
</div>
<div class="modal-body">
<form id="viewForm">

<div class="control-group">
<label class="control-label" for="tag_details">Select Tags:</label><p></p>
<div class="checkbox-new">
<?php foreach($tags as $tag): ?>

<input name='tag[]' class="checkbox" type="checkbox" value="<?php echo $tag['tag_code'] ?>"><?php echo $tag['tag_title'] ?></p>

<?php endforeach ?>
</div>
</div>
<div class="modal-footer">

<div class="btn-toolbar">
<button type="button" class="btn btn-default" class="pull-right" data-dismiss="modal">Close</button>
<input type="hidden" name="user_token" value="<?php echo $_SESSION['user_token']; ?>"/>
<button type="button" class="btn btn-success" class="pull-right">Add Tags <span class="glyphicon glyphicon-tags"/></button>

</div>
</div>
</form>
</div>
</div>
</div>
</div>


It currently looks like this:


First form


once filled in the user can then select 'Add tags' which will then open a second form as shown below: Second Form


I want to be able to grab the tags selected from the second form and put them as hidden values in the first form so its easier to send all that information to the process.php.


Any body know how i can achieve this? Or if theres an easier approach to doing this?


Aucun commentaire:

Enregistrer un commentaire