I am making a simple page and I have found this little problem. I have this in my template:
<?php foreach ($this->vypis_serie as $value) : ?>
<div class="serie">
<div id="serie_header">
<?= $value['nazev_cviceni'] ?>
</div>
<div id="serie_info">
<p>Number of excercises: TODO</p>
<p>Sport type: <?= $value['typ'] ?></p>
<p>KCal summary: <?= $value['kcal'] ?></p>
</div>
<div class="button_upravit">Edit</div>
<div class="button_smazat">Delete</div>
</div>
<?php endforeach; ?>
basically it is a block that fills in information about particular exercise (it is a sport app). SO If I have 3 entries in DB, it will print this code three times with corresponding info.
The problem I have is with the edit button, which upon clicking opens modal window. It is made purely with CSS, so no Javascript.
When I click the button, it jumps to this code:
<div id="openModal_edit" class="modalDialog">
<div>
X
<div id="editace">
<form id="platba" action="serie/edit/" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Edit serie</legend>
<ol>
<li>
<label for="name">Name of the series</label>
<input id="name" name="nazev_cviceni" type="text" required autofocus>
</li>
<li>
<label for="typ">Sport type</label>
<select name="typ">
<option value="Kolo">Bike</option>
<option value="Běhání" selected="selected">Running</option>
</select>
</li>
</ol>
</fieldset>
<fieldset>
<button type="submit">Save</button>
</fieldset>
</form>
</div>
</div>
</div>
But since I jump to div id and I am not using a new page where I could choose a controller and pass a variable, I need somehow to pass the variable (id of the exercise) to the modal window, so I can know which of the possible buttons I have clicked. Is there any way to do it, without the need to rewrite all other pages where I have used this modal window?
I can't use another foreach like in the first part, because the modal window is always a single object that appears, unlike all the entries on the page that are there as many times as there are entries in the DB.
Hope that it is understandable, sorry for my English :)
The simplest way to do this using a single modal window involves adding some javascript code to your page.
First, add the relevant information to the edit link, with a new data-serie-<name> for each piece of data you want to pass:
<a href="#openModal_edit" data-serie-name="<?= $value['nazev_cviceni'] ?>" ...>
Next, add an onclick event handler to that same link. This handler will extract the embedded data from the <a> element and inject it in the modal window. The dataset element provides access to the data-* attributes from javascript
// Example
onclick="serieName=this.dataset.serieName;document.querySelector('#openModal_edit input#name').value = serieName;return true;"
Related
I am working on a project where I need to pass an ID to controller when someone clicks on the link, and open response in new tab.
I googled for solution on this, but couldn't find proper result. I also tried by sending data through URL in anchor tag, but then it gave an error of config.php file, so I reversed the code.
Currently I am using form tag to pass data. Can ye do this using PHP, or will we have to take help of jquery?
Here's View code:
<form class="form-horizontal" method="post" action='<?php echo base_url() . "home/edit_policy"; ?>'>
<div class="form-group">
<input type="hidden" class="form-control" id="polid" name="polid" value="<?php echo $ajax_view_pol_response[0]->polid; ?>">
<div class="col-sm-offset-3 col-sm-3">
<button class="btn btn-primary" id="editpolsubmit">Edit this Policy</button>
</div>
</div>
</font>
This code is from Controller:
public function edit_policy() {
$polid = $this->input->post('polid');
}
I want to transfer the "polid" from view to controller function using anchor tag.
All positive suggestions are appreciated.
I want to submit my form in multiple tab using only one button but it is not working.I already put the button inside the form but it is also not working.Can I know what the solution to this problem?
<form method="POST">
<ul class="tab">
<li>DOCTOR'S DIAGNOSIS</li>
<li>OTHERS</li>
</ul>
<div id="diagnosis" class="tabcontent">Tarikh Penilaian : <input id="test_Date" name ="test_Date" type="date"></div>
<div id="others" class="tabcontent">Masa Penilaian : <input id="test_time" name ="test_time"></div>
<div><button type="submit" name="btn_reg" id="btn_reg"></button></div> </form>
I have a very simple form:
<form action="system/web/push.php" method="post">
<div class="row">
<div class="col card_input_push card_input_push_language">
<select name="<?php echo PARAM_PUSH_LANGUAGE; ?>">
<?php echo get_languages($mysqli); ?>
</select>
</div>
</div>
<div class="row">
<div class="col card_input card_input_push">
<input type="text" name="<?php echo PARAM_PUSH_TITLE; ?>" placeholder="<?php echo $language_array[LV_PUSH_INPUT_TITLE]; ?>"<?php echo set_value(PARAM_PUSH_TITLE); ?>required/>
</div>
</div>
<div class="row">
<div class="col card_input_push card_input_push_message">
<textarea name="<?php echo PARAM_PUSH_MESSAGE; ?>" placeholder="<?php echo $language_array[LV_PUSH_INPUT_MESSAGE]; ?>"<?php echo set_value(PARAM_PUSH_MESSAGE); ?>required></textarea>
</div>
</div>
<div class="row">
<div class="col text-center card_input_push card_button_push_send">
<button class="btn btn-default" type="submit" name="<?php echo REQUEST_SEND_GCM; ?>" value="<?php echo $language_array[LV_PUSH_INPUT_SEND]; ?>"><?php echo $language_array[LV_PUSH_INPUT_SEND]; ?></button>
</div>
</div>
</form>
When i now press the submit button i dont want the post to perform instantly. I first want a confirmation dialog to show up with yes or no answers and only if the user says yes i want the post action to be performed.
What i NOT want is to use JavaScript. Is there a way to do that?
EDIT
Thank's for the answers. To satisfy all respondents i would like to tell you, why i dont want to use JavaScript. The answer is simple. I have no idea about JavaScript. I never have used it before but the project im working on (as always) has to be finished ASAP. That's the only reason.
Yes there is a way, use GET (not POST) the first time, on the PHP file check if GET was used and if so generate a form that sends confirmation form back to the user. Then make confirmation form to submit using POST and you are done.
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// generate confirmation form
}elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
// process your data
}
If anyone has access to a book called Head First PHP-MySQL they cover a similar example on page 280.
Maybe you could do something like this, with some css for design your dialog.
change your form with :
<form action="this_page">
If you submit, you call this page, display the dialog with a form, and when you submit with second form, you post to your needed php file.
if (isset($_POST['your_submit'] )) {
echo "<yourdialog>";
echo "<form action="system/web/push.php">";
echo "content";
echo "<submit yes>";
echo "</form>";
echo "</yourdialog>";
}
Your workflow is:
gather form data
send to server
get confirmation that that's what the user wants.
if yes then process data.
If you want to do that all via php then the server's handling the full load, so you'll want two forms, one to collect and one to confirm. And you'll want to store the first form's data so you can process it according to the second form's result. A bit old fashioned but not difficult.
I am using the same view page for both submitting data to database and editing. When I submit the form all the elements go to database. When editing the input field contains the item to edit but the dropdown form doesnot load and displays error saying $expensetype not defined. the $expensetype is passed through the controller to the form. I am developing in pyrocms. Pyrocms is developed in Codeigniter.
<li>
<label for="expense_type_id">Expense Type</label> <!-- expense_type_id-->
<div class="input">
<?php echo form_dropdown("expense_type_id",$expensetype, set_value("expense_type_id", $expense_type_id)); ?>
</div>
</li><li>
<label for="expense_rs">Expense(NRS)</label> <!-- expense_rs-->
<div class="input">
<?php echo form_input("expense_rs", set_value("expense_rs", $expense_rs)); ?>
</div>
</li>
How to make the dropdown to show the item while editing.
have this following code:
<?php foreach ($arr_person as $new_person):?>
<div id= "demo">
<div id= "dialog">
</div>
<input type="button" id="botton" name="botton">
</div>
<?php endforeach; ?>
In the press button run a dialog!
more, the code load everything buttons.
This can't ever work with jquery, because you CAN'T have multiple elements with same id attribute.
change all same ids to classes and also change them in jQuery (# to .) and it should work