douchen2025 2015-08-05 06:57
浏览 94

使用PHP或JavaScript将属性连接到属性

I have the following part of code in my file.

<?php
$output = "<font id=''>" . $_POST["input"] . "</font>";
file_put_contents("output.html", $output, FILE_APPEND);
?>

The user can submit the form several times, and each time, the value entered in the input-field will be saved into a file. What I want to do, either with PHP or JavaScript, is to add consecutive numbers in the id attribute for each value submitted.

Example: user enters <kbd>hello</kbd> and submits form. Only <font id=''>hello</font> will be written into the file. What I want to do is to write 1 in the id attribute for the first value submitted (<font id='1'>hello</font>). For the second value, to be written 2, 3 for the third value, etc.

Is it possible to do this? If so, how?

Thank you.

  • 写回答

2条回答 默认 最新

  • doudiandi6967 2015-08-05 07:15
    关注

    It's difficult have a count of submit, because when you do the submit, a variable in javascript will lose the counter, and in php too.

    So my idea it's use AJAX to do the submit, and you have a counter in Javascript that it starts at 1. When submit, increment this counter and pass the counter like other input hidden.

    In summary, I have a form with 2 inputs, the one you have, and other hidden in which you put the counter of submits. You do the submit using ajax, and the page not reload. So you can have the counter to add in the file like other $_POST['counter'].

    Try this and tell me if this be useful.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题