Jump to content

send my info through a form


loxfear

Recommended Posts

this is my code:

<?php
include 'sqlconnect.php';

$sql = mysqli_query($con,"SELECT * FROM aktiviteter");
$data = array();
while ($row = mysqli_fetch_assoc($sql))
{
    $data[$row['id']] = array(
        'title' => $row['title'],
        'pris'  => $row['pris'],
		'beskrivelse' => $row['beskrivelse'],
    );
}
print_r(error_get_last());
?>

<html>
<head>
<title>Polterplanner Bestilling</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
    var jsArray = [];
    <?php
foreach($data as $key => $value):
echo 'jsArray["'.$key.'"] = [];';
echo "\r\n";
    foreach($value as $infoType => $info):
echo 'jsArray["'.$key.'"]["'.$infoType.'"] = "'.$info.'";';
echo "\r\n";
endforeach;
endforeach;
print_r(error_get_last());
?>
function activitySelectionChanged(elementID) {
        var activitySelect = document.getElementById('activity' + elementID);
        var selectedValue = activitySelect.value;
        var priceOutputBox = document.getElementById('activityPrice' + elementID);
        priceOutputBox.innerHTML = jsArray[selectedValue]["pris"];

        var price1 = document.getElementById('activityPrice').innerHTML;
        var price2 = document.getElementById('activityPrice2').innerHTML;
        var total  = document.getElementById('activityTotal');
        if(price1!='Pris' && price2!='Pris') {
            total.innerHTML = parseInt(price1) + parseInt(price2);
       }
    }

</script>
</head>
<body>

<div id"wrapper">
  <div id="tableWrapper">

    <table class="tables" width="349" height="27" border="0">
      <tr>
        <td width="174" height="23">
          <select class="styled-select" name="activity" id="activity" onChange="activitySelectionChanged('')">
          <option value="">-----------------</option>
          <?php
    foreach($data as $key => $value):
    echo '<option value="'.$key.'">'.$value['title'].'</option>';
    echo "\r\n";
    endforeach;

    print_r(error_get_last());
    ?>
        </select></td>
        <td width="86"> </td>
        <td width="75"><span class="Pris" id="activityPrice">Pris</span>,-</td>
      </tr>
    </table>

    <table class="tables" width="349" height="27" border="0">
      <tr>
        <td width="174" height="23">
          <select class="styled-select" name="activity2" id="activity2" onChange="activitySelectionChanged(2)">
          <option value="">-----------------</option>
          <?php
          foreach($data as $key => $value):
            echo '<option value="'.$key.'">'.$value['title'].'</option>';
            echo "\r\n";
            print_r(error_get_last());
          endforeach;
    ?>
        </select></td>
        <td width="86"> </td>
        <td width="75"><span class="Pris" id="activityPrice2">Pris</span>,-</td>
      </tr>
    </table>

    <table class="tables" width="349" height="27" border="0">
      <tr>
        <td width="174" height="27">Total:</td>
        <td width="86"> </td>
        <td width="75"><span class="Pris" id="activityTotal">Total</span>,-</td>
    </tr>
    </table>

  </div> <!-- tableWrapper ends -->
</div> <!-- wrapper ends -->

</body>
</html>





what i want is the info send through a form, so that im ale to send this via an email.

would i use: document.getElementById( ...... ); ?

 

link to working page: http://polterplanner.dk/bestiller.php

Link to comment
Share on other sites

It's unclear what you want, which is probably why nobody hasn't answered yet.

 

What do you mean by “send info through a form”?  Do you want to submit the selected options to another script? Then why not use an actual form? That's what they're for.

 

Generating dynamic JavaScript code is actually a very bad idea, because you easily end up with cross-site scripting vulnerabilities or plain bugs. For example, if there's any single quote in your data, your whole script blows up with a syntax error. That's hardly a good solution.

 

Instead, simply store the price in a data attribute in the option element itself. Or load the data with an Ajax request. Or JSON-encode the data, HTML-escape it and then put it into a hidden div element. But do not drop PHP values into a script element. That's really the worst of all approaches.

Link to comment
Share on other sites

The keys are already in the value attribute of the option. They're sent automatically.

 

Or are you talking about the price, the title etc.? You do not need to send those. You already have them in your database and can look them up at any time, so all you need to send is the key.

Link to comment
Share on other sites

Using the submitted value to look up all the other data is the biggest issue, and how to submit the data i need, or is the selecter able to do that?

 

ps. sorry for the vague question

Edited by loxfear
Link to comment
Share on other sites

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.