2016-04-26 10 views
1

Я проверяю форму с использованием PHP (очень простая базовая форма) и им интересно, есть ли решение, чтобы не получить эту ошибку. Уведомление: Неопределенный индекс: sendMethod in/directory/... on line 26 вот мой код, который у меня есть для моей формы:Уведомление об ошибке PHP на кнопке радиосвязи

<form name="myForm" id="userDetails" action="formProcess.php" onSubmit="return validateForm()" method="post"> 
 
    <fieldset class="custInf"> 
 
    <h3> User Details </h3> 
 
    <label class="inputArea" for="fName">Forename :</label> 
 
    <input type="text" name="forename" id="fname" placeholder="Enter First Name" maxlength="20" size="15"> 
 
    </input> 
 
    <label class="inputArea" for="sName">Surname :</label> 
 
    <input type="text" name="surname" id="surname" placeholder="Enter Last Name" maxlength="20" size="15"> 
 
    </input> 
 
    <label class="inputArea" for="email">Email :</label> 
 
    <input type="email" name="email" id="email" placeholder="Enter Email Address" maxlength="40" size="15" /> 
 
    </input> 
 
    <label class="inputArea" for="hmph">Landline number :</label> 
 
    <input type="tel" name="landLineTelNo" id="hmphone" placeholder="Enter Landline no." maxlength="11" size="15"> 
 
    </input> 
 
    <label class="inputArea" for="mobileTelNo">Mobile number :</label> 
 
    <input type="tel" name="mobileTelNo" id="mobile" placeholder="Enter Mobile no." maxlength="11" size="15"> 
 
    </input> 
 
    <label class="inputArea" for="address">Postal Address :</label> 
 
    <input type="text" name="postalAddress" id="address" placeholder="Enter House no." maxlength="25" size="15"> 
 
    </input> 
 
    </fieldset> 
 
    <fieldset class="contactType"> 
 
    <h3> How would you like to be contacted? </h3> 
 
    <label class="radioBt" for="sms">SMS</label> 
 
    <input id="smsBut" type="radio" name="sendMethod" value="SMS"> 
 
    </input> 
 
    <label class="radioBt" for="email">Email</label> 
 
    <input type="radio" name="sendMethod" value="Email"> 
 
    </input> 
 
    <label class="radioBt" for="post">Post</label> 
 
    <input type="radio" name="sendMethod" value="Post"> 
 
    </input> 
 
    </fieldset> 
 
    <fieldset class="termsCon"> 
 
    <input type="checkbox" name="check" value="check" id="check" />I have read and agree to the Terms and Conditions and Privacy Policy 
 
    </input> 
 
    </fieldset> 
 
    <input class="submitBut" type="submit" name="submitBut" value="Submit" </input> 
 
</form>

$fname = $_REQUEST['forename']; 
if (empty($fname)) { 
die("<p>Enter a first name</p>\n"); 
} 

$surname = $_REQUEST['surname']; 
if (empty($surname)) { 
die("<p>You must enter a surname</p>\n"); 
} 

$email = $_REQUEST['email']; 
if (empty($email)) { 
die("<p>You need to enter an email</p>\n"); 
} 
//Landline not required so wont give error 
$hmphone = isset($_REQUEST['hmph']) ? $_REQUEST['hmph'] : null ; 

$mobile = $_REQUEST['mobileTelNo']; 
if (empty($mobile)) { 
die("<p>Enter a Mobile Number</p>\n"); 
} 

$address = $_REQUEST['postalAddress']; 
if (empty($address)) { 
die("<p>Enter your postal address</p>\n"); 
} 

$sendMethod = $_REQUEST['sendMethod']; 
if (empty($sendMethod)) { 
die("<p>Please choose a contact option</p>\n"); 
} 

$check = $_REQUEST['check']; 
if (empty($check)) { 
die("<p>Please select the Terms and Conditions to continue</p>\n"); 
} 

его очень простой проверки PHP, я просто хочу, чтобы не дать мне уведомление об ошибке, пока во всем поля были проверены, например, e rror появляется, как только все поля заполняются словами «Пожалуйста, выберите контакт», но если я заполню все поля на мобильном телефоне, я получаю сообщение об ошибке

ответ

0

, чтобы избежать уведомления, проверьте, действительно ли это empty

if (empty($_REQUEST['sendMethod'])) 
    die("<p>Please choose a contact option</p>\n"); 
else 
    $sendMethod = $_REQUEST['sendMethod']; 
+0

хорошо, а им все еще получаю сообщение об ошибке, но это было причиной этой строки кода $ sendMethod = $ _POST [ «sendMethod»]; – OliverQueen

+0

Какая ошибка? –

+0

sec i не знаю, как сделать код в комментариях ill copy paste something – OliverQueen

Смежные вопросы